crypto/virtio: vDPA and asymmetric support
Subsystems (5)
cover crypto/virtio: vDPA and asymmetric support
This series introduces vDPA backend support to virtio crypto PMD. Also added asymmetric RSA support.
Gowrishankar Muthukrishnan (14):
vhost: include AKCIPHER algorithms in crypto_config crypto/virtio: add asymmetric RSA support test/crypto: check for RSA capability test/crypto: add asymmetric tests for virtio PMD
vhost: add asymmetric RSA support examples/vhost_crypto: add asymmetric support crypto/virtio: fix dataqueues iteration crypto/virtio: refactor queue operations crypto/virtio: add packed ring support common/virtio: common virtio log common/virtio: move vDPA to common directory common/virtio: support cryptodev in vdev setup crypto/virtio: add vhost backend to virtio_user test/crypto: test virtio_crypto_user PMD
Rajesh Mudimadugula (2):
crypto/virtio: remove redundant crypto queue free test/crypto: return proper codes in create session
.mailmap | 1 +
app/test/test_cryptodev.c | 45 +-
app/test/test_cryptodev.h | 1 +
app/test/test_cryptodev_asym.c | 68 +
app/test/test_cryptodev_rsa_test_vectors.h | 4 +
drivers/common/virtio/meson.build | 13 +
drivers/common/virtio/version.map | 9 +
drivers/{net => common}/virtio/virtio_logs.h | 16 +-
.../virtio/virtio_user/vhost.h | 2 -
.../virtio/virtio_user/vhost_vdpa.c | 31 +-
drivers/crypto/virtio/meson.build | 11 +-
drivers/crypto/virtio/virtio_crypto_algs.h | 2 +-
.../virtio/virtio_crypto_capabilities.h | 19 +
.../{virtio_logs.h => virtio_crypto_logs.h} | 30 +-
drivers/crypto/virtio/virtio_cryptodev.c | 1105 +++++++++++------
drivers/crypto/virtio/virtio_cryptodev.h | 16 +-
drivers/crypto/virtio/virtio_cvq.c | 229 ++++
drivers/crypto/virtio/virtio_cvq.h | 33 +
drivers/crypto/virtio/virtio_pci.h | 38 +-
drivers/crypto/virtio/virtio_ring.h | 65 +-
drivers/crypto/virtio/virtio_rxtx.c | 707 ++++++++++-
drivers/crypto/virtio/virtio_rxtx.h | 13 +
.../crypto/virtio/virtio_user/vhost_vdpa.c | 310 +++++
.../virtio/virtio_user/virtio_user_dev.c | 774 ++++++++++++
.../virtio/virtio_user/virtio_user_dev.h | 88 ++
drivers/crypto/virtio/virtio_user_cryptodev.c | 586 +++++++++
drivers/crypto/virtio/virtqueue.c | 229 +++-
drivers/crypto/virtio/virtqueue.h | 223 +++-
drivers/meson.build | 1 +
drivers/net/virtio/meson.build | 4 +-
drivers/net/virtio/virtio.c | 3 +-
drivers/net/virtio/virtio_ethdev.c | 5 +-
drivers/net/virtio/virtio_net_logs.h | 30 +
drivers/net/virtio/virtio_pci.c | 3 +-
drivers/net/virtio/virtio_pci_ethdev.c | 3 +-
drivers/net/virtio/virtio_rxtx.c | 3 +-
drivers/net/virtio/virtio_rxtx_packed.c | 3 +-
drivers/net/virtio/virtio_rxtx_packed.h | 3 +-
drivers/net/virtio/virtio_rxtx_packed_avx.h | 3 +-
drivers/net/virtio/virtio_rxtx_simple.h | 3 +-
drivers/net/virtio/virtio_user/vhost_kernel.c | 4 +-
.../net/virtio/virtio_user/vhost_kernel_tap.c | 3 +-
drivers/net/virtio/virtio_user/vhost_user.c | 2 +-
.../net/virtio/virtio_user/virtio_user_dev.c | 6 +-
.../net/virtio/virtio_user/virtio_user_dev.h | 24 +-
drivers/net/virtio/virtio_user_ethdev.c | 5 +-
drivers/net/virtio/virtqueue.c | 3 +-
drivers/net/virtio/virtqueue.h | 3 +-
examples/vhost_crypto/main.c | 54 +-
lib/cryptodev/cryptodev_pmd.h | 6 +
lib/vhost/vhost_crypto.c | 504 +++++++-
lib/vhost/vhost_user.h | 33 +-
lib/vhost/virtio_crypto.h | 82 +-
53 files changed, 4846 insertions(+), 615 deletions(-)
create mode 100644 drivers/common/virtio/meson.build
create mode 100644 drivers/common/virtio/version.map
rename drivers/{net => common}/virtio/virtio_logs.h (61%)
rename drivers/{net => common}/virtio/virtio_user/vhost.h (98%)
rename drivers/{net => common}/virtio/virtio_user/vhost_vdpa.c (96%)
rename drivers/crypto/virtio/{virtio_logs.h => virtio_crypto_logs.h} (74%)
create mode 100644 drivers/crypto/virtio/virtio_cvq.c
create mode 100644 drivers/crypto/virtio/virtio_cvq.h
create mode 100644 drivers/crypto/virtio/virtio_rxtx.h
create mode 100644 drivers/crypto/virtio/virtio_user/vhost_vdpa.c
create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.c
create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.h
create mode 100644 drivers/crypto/virtio/virtio_user_cryptodev.c
create mode 100644 drivers/net/virtio/virtio_net_logs.hSignature · 1 line
2.25.1
PATCH 1/16 vhost: include AKCIPHER algorithms in crypto_config
Update virtio_crypto_config structure to include AKCIPHER algorithms, as per VirtIO standard.
--- lib/vhost/virtio_crypto.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/vhost/virtio_crypto.h +1 -1
@@ -410,7 +410,7 @@ struct virtio_crypto_config {uint32_t max_cipher_key_len;/* Maximum length of authenticated key */ uint32_t max_auth_key_len; -uint32_t reserve; +uint32_t akcipher_algo;/* Maximum size of each crypto request's content */ uint64_t max_size; };
Signature · 1 line
2.25.1
PATCH 2/16 crypto/virtio: remove redundant crypto queue free
In reply to Gowrishankar MuthukrishnanFrom: Rajesh Mudimadugula <[email protected]>
Remove multiple invocations of virtio_crypto_queue_release, and set virtio crypto queue as null upon free to avoid segfaults.
--- .mailmap | 1 + drivers/crypto/virtio/virtio_cryptodev.c | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-)
.mailmap +1 -0
@@ -1247,6 +1247,7 @@ Rahul Gupta <[email protected]> Rahul Lakkireddy <[email protected]> Rahul Shah <[email protected]> Raja Zidane <[email protected]> +Rajesh Mudimadugula <[email protected]> Rajesh Ravi <[email protected]> Rakesh Kudurumalla <[email protected]> <[email protected]> Ralf Hoffmann <[email protected]>
drivers/crypto/virtio/virtio_cryptodev.c +5 -6
@@ -478,10 +478,13 @@ virtio_crypto_free_queues(struct rte_cryptodev *dev)/* control queue release */ virtio_crypto_queue_release (hw->cvq); + hw->cvq =NULL ;/* data queue release */ -for (i =0 ; i < hw->max_dataqueues; i++) +for (i =0 ; i < hw->max_dataqueues; i++) {virtio_crypto_queue_release (dev->data->queue_pairs[i]); + dev->data->queue_pairs[i] =NULL ; + } } static int
@@ -613,6 +616,7 @@ virtio_crypto_qp_release(struct rte_cryptodev *dev, uint16_t queue_pair_id) }virtio_crypto_queue_release (vq); + dev->data->queue_pairs[queue_pair_id] =NULL ;return 0 ; }
@@ -760,8 +764,6 @@ crypto_virtio_create(const char *name, struct rte_pci_device *pci_dev,static int virtio_crypto_dev_uninit (struct rte_cryptodev *cryptodev) { -struct virtio_crypto_hw *hw = cryptodev->data->dev_private; -PMD_INIT_FUNC_TRACE ();if (rte_eal_process_type () ==RTE_PROC_SECONDARY )
@@ -776,9 +778,6 @@ virtio_crypto_dev_uninit(struct rte_cryptodev *cryptodev) cryptodev->enqueue_burst =NULL ; cryptodev->dequeue_burst =NULL ; -/* release control queue */ -virtio_crypto_queue_release (hw->cvq); -rte_free (cryptodev->data); cryptodev->data =NULL ;
Signature · 1 line
2.25.1
PATCH 3/16 crypto/virtio: add asymmetric RSA support
In reply to Gowrishankar MuthukrishnanAsymmetric RSA operations (SIGN, VERIFY, ENCRYPT and DECRYPT) are supported in virtio PMD.
--- .../virtio/virtio_crypto_capabilities.h | 19 + drivers/crypto/virtio/virtio_cryptodev.c | 384 +++++++++++++++--- drivers/crypto/virtio/virtio_rxtx.c | 226 ++++++++++- lib/cryptodev/cryptodev_pmd.h | 6 + lib/vhost/virtio_crypto.h | 80 ++++ 5 files changed, 647 insertions(+), 68 deletions(-)
drivers/crypto/virtio/virtio_crypto_capabilities.h +19 -0
@@ -48,4 +48,23 @@ }, } \ } +#define VIRTIO_ASYM_CAPABILITIES \ + { /* RSA */ \ + .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC, \ + {.asym = { \ + .xform_capa = { \ + .xform_type = RTE_CRYPTO_ASYM_XFORM_RSA, \ + .op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) | \ + (1 << RTE_CRYPTO_ASYM_OP_VERIFY) | \ + (1 << RTE_CRYPTO_ASYM_OP_ENCRYPT) | \ + (1 << RTE_CRYPTO_ASYM_OP_DECRYPT)), \ + {.modlen = { \ + .min = 1, \ + .max = 1024, \ + .increment = 1 \ + }, } \ + } \ + }, } \ + } +#endif /* _VIRTIO_CRYPTO_CAPABILITIES_H_ */
drivers/crypto/virtio/virtio_cryptodev.c +332 -52
478 lines not on this page · raw message
drivers/crypto/virtio/virtio_rxtx.c +210 -16
249 lines not on this page · raw message
lib/cryptodev/cryptodev_pmd.h +6 -0
@@ -715,6 +715,12 @@ struct rte_cryptodev_asym_session {uint8_t sess_private_data[]; }; +/** +* Helper macro to get session private data +*/ +#define CRYPTODEV_GET_ASYM_SESS_PRIV (s) \ + ((void *)(((struct rte_cryptodev_asym_session *)s)->sess_private_data)) + #ifdef __cplusplus }#endif
lib/vhost/virtio_crypto.h +80 -0
128 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 4/16 test/crypto: check for RSA capability
In reply to Gowrishankar MuthukrishnanIn RSA crypto tests, check if it is supported by PMD before executing it.
--- app/test/test_cryptodev_asym.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+)
app/test/test_cryptodev_asym.c +24 -0
@@ -234,11 +234,17 @@ test_rsa_sign_verify(void) {struct crypto_testsuite_params_asym *ts_params = &testsuite_params;struct rte_mempool *sess_mpool = ts_params->session_mpool; +struct rte_cryptodev_asym_capability_idx idx;uint8_t dev_id = ts_params->valid_devs[0 ];void *sess =NULL ;struct rte_cryptodev_info dev_info;int ret, status =TEST_SUCCESS ; +/* Check RSA capability */ + idx.type =RTE_CRYPTO_ASYM_XFORM_RSA ; +if (rte_cryptodev_asym_capability_get (dev_id, &idx) ==NULL ) +return -ENOTSUP ; +/* Test case supports op with exponent key only, * Check in PMD feature flag for RSA exponent key type support. */
@@ -274,11 +280,17 @@ test_rsa_enc_dec(void) {struct crypto_testsuite_params_asym *ts_params = &testsuite_params;struct rte_mempool *sess_mpool = ts_params->session_mpool; +struct rte_cryptodev_asym_capability_idx idx;uint8_t dev_id = ts_params->valid_devs[0 ];void *sess =NULL ;struct rte_cryptodev_info dev_info;int ret, status =TEST_SUCCESS ; +/* Check RSA capability */ + idx.type =RTE_CRYPTO_ASYM_XFORM_RSA ; +if (rte_cryptodev_asym_capability_get (dev_id, &idx) ==NULL ) +return -ENOTSUP ; +/* Test case supports op with exponent key only, * Check in PMD feature flag for RSA exponent key type support. */
@@ -314,11 +326,17 @@ test_rsa_sign_verify_crt(void) {struct crypto_testsuite_params_asym *ts_params = &testsuite_params;struct rte_mempool *sess_mpool = ts_params->session_mpool; +struct rte_cryptodev_asym_capability_idx idx;uint8_t dev_id = ts_params->valid_devs[0 ];void *sess =NULL ;struct rte_cryptodev_info dev_info;int ret, status =TEST_SUCCESS ; +/* Check RSA capability */ + idx.type =RTE_CRYPTO_ASYM_XFORM_RSA ; +if (rte_cryptodev_asym_capability_get (dev_id, &idx) ==NULL ) +return -ENOTSUP ; +/* Test case supports op with quintuple format key only, * Check im PMD feature flag for RSA quintuple key type support. */
@@ -354,11 +372,17 @@ test_rsa_enc_dec_crt(void) {struct crypto_testsuite_params_asym *ts_params = &testsuite_params;struct rte_mempool *sess_mpool = ts_params->session_mpool; +struct rte_cryptodev_asym_capability_idx idx;uint8_t dev_id = ts_params->valid_devs[0 ];void *sess =NULL ;struct rte_cryptodev_info dev_info;int ret, status =TEST_SUCCESS ; +/* Check RSA capability */ + idx.type =RTE_CRYPTO_ASYM_XFORM_RSA ; +if (rte_cryptodev_asym_capability_get (dev_id, &idx) ==NULL ) +return -ENOTSUP ; +/* Test case supports op with quintuple format key only, * Check in PMD feature flag for RSA quintuple key type support. */
Signature · 1 line
2.25.1
PATCH 5/16 test/crypto: return proper codes in create session
In reply to Gowrishankar MuthukrishnanFrom: Rajesh Mudimadugula <[email protected]>
Return proper error codes in create_auth_session() to avoid segfaults as a result of this.
--- app/test/test_cryptodev.c | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-)
app/test/test_cryptodev.c +28 -10
@@ -13006,6 +13006,8 @@ test_cryptodev_error_recover_helper(uint8_t dev_id, const void *test_data, bool ut_params->sess =rte_cryptodev_sym_session_create (dev_id, &ut_params->cipher_xform, ts_params->session_mpool); +if (ut_params->sess ==NULL && rte_errno ==ENOTSUP ) +return TEST_SKIPPED ;TEST_ASSERT_NOT_NULL (ut_params->sess,"Session creation failed" ); ut_params->op =rte_crypto_op_alloc (ts_params->op_mpool,RTE_CRYPTO_OP_TYPE_SYMMETRIC );
@@ -14707,15 +14709,19 @@ test_multi_session(void) sessions[i] =rte_cryptodev_sym_session_create ( ts_params->valid_devs[0 ], &ut_params->auth_xform, ts_params->session_mpool); -if (sessions[i] ==NULL && rte_errno ==ENOTSUP ) { +if (sessions[i] ==NULL ) { nb_sess = i; - ret =TEST_SKIPPED ; +if (rte_errno ==ENOTSUP ) + ret =TEST_SKIPPED ; +else { + ret =TEST_FAILED ; +printf ("TestCase %s() line %d failed : " +"Session creation failed at session number %u" , + __func__, __LINE__, i); + }break ; } -TEST_ASSERT_NOT_NULL (sessions[i], -"Session creation failed at session number %u" , - i);/* Attempt to send a request on each session */ ret = test_AES_CBC_HMAC_SHA512_decrypt_perform(
@@ -14843,15 +14849,19 @@ test_multi_session_random_usage(void) ts_params->valid_devs[0 ], &ut_paramz[i].ut_params.auth_xform, ts_params->session_mpool); -if (sessions[i] ==NULL && rte_errno ==ENOTSUP ) { +if (sessions[i] ==NULL ) { nb_sess = i; - ret =TEST_SKIPPED ; +if (rte_errno ==ENOTSUP ) + ret =TEST_SKIPPED ; +else { + ret =TEST_FAILED ; +printf ("TestCase %s() line %d failed : " +"Session creation failed at session number %u" , + __func__, __LINE__, i); + } goto session_clear; } -TEST_ASSERT_NOT_NULL (sessions[i], -"Session creation failed at session number %u" , - i); } nb_sess = i;
@@ -14934,6 +14944,8 @@ test_null_invalid_operation(void) ut_params->sess =rte_cryptodev_sym_session_create ( ts_params->valid_devs[0 ], &ut_params->cipher_xform, ts_params->session_mpool); +if (ut_params->sess ==NULL && rte_errno ==ENOTSUP ) +return TEST_SKIPPED ;TEST_ASSERT (ut_params->sess ==NULL ,"Session creation succeeded unexpectedly" );
@@ -14948,6 +14960,8 @@ test_null_invalid_operation(void) ut_params->sess =rte_cryptodev_sym_session_create ( ts_params->valid_devs[0 ], &ut_params->auth_xform, ts_params->session_mpool); +if (ut_params->sess ==NULL && rte_errno ==ENOTSUP ) +return TEST_SKIPPED ;TEST_ASSERT (ut_params->sess ==NULL ,"Session creation succeeded unexpectedly" );
@@ -15095,6 +15109,8 @@ test_enqdeq_callback_null_cipher(void)/* Create Crypto session */ ut_params->sess =rte_cryptodev_sym_session_create (ts_params->valid_devs[0 ], &ut_params->auth_xform, ts_params->session_mpool); +if (ut_params->sess ==NULL && rte_errno ==ENOTSUP ) +return TEST_SKIPPED ;TEST_ASSERT_NOT_NULL (ut_params->sess,"Session creation failed" ); ut_params->op =rte_crypto_op_alloc (ts_params->op_mpool,RTE_CRYPTO_OP_TYPE_SYMMETRIC );
@@ -16155,6 +16171,7 @@ create_auth_session(struct crypto_unittest_params *ut_params, ts_params->session_mpool);if (ut_params->sess ==NULL && rte_errno ==ENOTSUP )return TEST_SKIPPED ; +TEST_ASSERT_NOT_NULL (ut_params->sess,"Session creation failed" );return 0 ; }
@@ -16205,6 +16222,7 @@ create_auth_cipher_session(struct crypto_unittest_params *ut_params, ts_params->session_mpool);if (ut_params->sess ==NULL && rte_errno ==ENOTSUP )return TEST_SKIPPED ; +TEST_ASSERT_NOT_NULL (ut_params->sess,"Session creation failed" );return 0 ; }
Signature · 1 line
2.25.1
PATCH 6/16 test/crypto: add asymmetric tests for virtio PMD
In reply to Gowrishankar MuthukrishnanAdd asymmetric tests for Virtio PMD.
--- app/test/test_cryptodev_asym.c | 29 ++++++++++++++++++++++ app/test/test_cryptodev_rsa_test_vectors.h | 4 +++ 2 files changed, 33 insertions(+)
app/test/test_cryptodev_asym.c +29 -0
@@ -3997,6 +3997,19 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite = { } }; +static struct unit_test_suite cryptodev_virtio_asym_testsuite = { + .suite_name ="Crypto Device VIRTIO ASYM Unit Test Suite" , + .setup = testsuite_setup, + .teardown = testsuite_teardown, + .unit_test_cases = { +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, test_capability), +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, + test_rsa_sign_verify_crt), +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec_crt), +TEST_CASES_END ()/**< NULL terminate unit test array */ + } +}; +static int test_cryptodev_openssl_asym (void ) {
@@ -4065,6 +4078,22 @@ test_cryptodev_cn10k_asym(void)return unit_test_suite_runner (&cryptodev_octeontx_asym_testsuite); } +static int +test_cryptodev_virtio_asym (void ) +{ + gbl_driver_id =rte_cryptodev_driver_id_get ( +RTE_STR (CRYPTODEV_NAME_VIRTIO_PMD )); +if (gbl_driver_id ==-1 ) { +RTE_LOG (ERR ,USER1 ,"virtio PMD must be loaded.\n" ); +return TEST_FAILED ; + } + +/* Use test suite registered for crypto_virtio PMD */ +return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); +} + +REGISTER_DRIVER_TEST (cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym); +REGISTER_DRIVER_TEST (cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);REGISTER_DRIVER_TEST (cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);REGISTER_DRIVER_TEST (cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);
app/test/test_cryptodev_rsa_test_vectors.h +4 -0
@@ -377,6 +377,10 @@ struct rte_crypto_asym_xform rsa_xform_crt = { .length = sizeof(rsa_e) }, .key_type = RTE_RSA_KEY_TYPE_QT, + .d = { + .data = rsa_d, + .length =sizeof (rsa_d) + }, .qt = { .p = { .data = rsa_p,
Signature · 1 line
2.25.1
PATCH 7/16 vhost: add asymmetric RSA support
In reply to Gowrishankar MuthukrishnanSupport asymmetric RSA crypto operations in vhost-user.
--- lib/vhost/vhost_crypto.c | 504 ++++++++++++++++++++++++++++++++++++--- lib/vhost/vhost_user.h | 33 ++- 2 files changed, 498 insertions(+), 39 deletions(-)
lib/vhost/vhost_crypto.c +469 -35
@@ -54,6 +54,14 @@ RTE_LOG_REGISTER_SUFFIX(vhost_crypto_logtype, crypto, INFO);*/ #define vhost_crypto_desc vring_desc +struct vhost_crypto_session { +union { +struct rte_cryptodev_asym_session *asym; +struct rte_cryptodev_sym_session *sym; + }; +enum rte_crypto_op_type type; +}; +static int cipher_algo_transform (uint32_t virtio_cipher_algo,enum rte_crypto_cipher_algorithm *algo)
@@ -206,8 +214,10 @@ struct __rte_cache_aligned vhost_crypto {uint64_t last_session_id; -uint64_t cache_session_id; -struct rte_cryptodev_sym_session *cache_session; +uint64_t cache_sym_session_id; +struct rte_cryptodev_sym_session *cache_sym_session; +uint64_t cache_asym_session_id; +struct rte_cryptodev_asym_session *cache_asym_session;/** socket id for the device */ int socket_id;
@@ -237,7 +247,7 @@ struct vhost_crypto_data_req {static int transform_cipher_param (struct rte_crypto_sym_xform *xform, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {int ret;
@@ -273,7 +283,7 @@ transform_cipher_param(struct rte_crypto_sym_xform *xform,static int transform_chain_param (struct rte_crypto_sym_xform *xforms, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {struct rte_crypto_sym_xform *xform_cipher, *xform_auth;int ret;
@@ -334,17 +344,17 @@ transform_chain_param(struct rte_crypto_sym_xform *xforms, }static void -vhost_crypto_create_sess (struct vhost_crypto *vcrypto, +vhost_crypto_create_sym_sess (struct vhost_crypto *vcrypto,VhostUserCryptoSessionParam *sess_param) {struct rte_crypto_sym_xform xform1 = {0 }, xform2 = {0 };struct rte_cryptodev_sym_session *session;int ret; -switch (sess_param->op_type) { +switch (sess_param->u.sym_sess.op_type) {case VIRTIO_CRYPTO_SYM_OP_NONE :case VIRTIO_CRYPTO_SYM_OP_CIPHER : - ret =transform_cipher_param (&xform1, sess_param); + ret =transform_cipher_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session msg (%i)" , ret); sess_param->session_id = ret;
@@ -352,7 +362,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, }break ;case VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING : -if (unlikely (sess_param->hash_mode != +if (unlikely (sess_param->u.sym_sess.hash_mode !=VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH )) { sess_param->session_id = -VIRTIO_CRYPTO_NOTSUPP ; VC_LOG_ERR("Error transform session message (%i)",
@@ -362,7 +372,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, xform1.next = &xform2; - ret =transform_chain_param (&xform1, sess_param); + ret =transform_chain_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session message (%i)" , ret); sess_param->session_id = ret;
@@ -402,22 +412,264 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, vcrypto->last_session_id++; } +static int +tlv_decode (uint8_t *tlv,uint8_t type,uint8_t **data,size_t *data_len) +{ +size_t tlen = -EINVAL , len; + +if (tlv[0 ] != type) +return -EINVAL ; + +if (tlv[1 ] ==0x82 ) { + len = (tlv[2 ] <<8 ) | tlv[3 ]; + *data =rte_malloc (NULL , len,0 ); +rte_memcpy (*data, &tlv[4 ], len); + tlen = len +4 ; + }else if (tlv[1 ] ==0x81 ) { + len = tlv[2 ]; + *data =rte_malloc (NULL , len,0 ); +rte_memcpy (*data, &tlv[3 ], len); + tlen = len +3 ; + }else { + len = tlv[1 ]; + *data =rte_malloc (NULL , len,0 ); +rte_memcpy (*data, &tlv[2 ], len); + tlen = len +2 ; + } + + *data_len = len; +return tlen; +} + +static int +virtio_crypto_asym_rsa_der_to_xform (uint8_t *der,size_t der_len, +struct rte_crypto_asym_xform *xform) +{ +uint8_t *n =NULL , *e =NULL , *d =NULL , *p =NULL , *q =NULL , *dp =NULL , + *dq =NULL , *qinv =NULL , *v =NULL , *tlv; +size_t nlen, elen, dlen, plen, qlen, dplen, dqlen, qinvlen, vlen; +int len; + +RTE_SET_USED (der_len); + +if (der[0 ] !=0x30 ) +return -EINVAL ; + +if (der[1 ] ==0x82 ) + tlv = &der[4 ]; +else if (der[1 ] ==0x81 ) + tlv = &der[3 ]; +else +return -EINVAL ; + + len =tlv_decode (tlv,0x02 , &v, &vlen); +if (len <0 || v[0 ] !=0x0 || vlen !=1 ) { + len = -EINVAL ; + goto _error; + } + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &n, &nlen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &e, &elen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &d, &dlen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &p, &plen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &q, &qlen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &dp, &dplen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &dq, &dqlen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &qinv, &qinvlen); +if (len <0 ) + goto _error; + + xform->rsa.n.data = n; + xform->rsa.n.length = nlen; + xform->rsa.e.data = e; + xform->rsa.e.length = elen; + xform->rsa.d.data = d; + xform->rsa.d.length = dlen; + xform->rsa.qt.p.data = p; + xform->rsa.qt.p.length = plen; + xform->rsa.qt.q.data = q; + xform->rsa.qt.q.length = qlen; + xform->rsa.qt.dP.data = dp; + xform->rsa.qt.dP.length = dplen; + xform->rsa.qt.dQ.data = dq; + xform->rsa.qt.dQ.length = dqlen; + xform->rsa.qt.qInv.data = qinv; + xform->rsa.qt.qInv.length = qinvlen; + +RTE_ASSERT ((tlv + len - &der[0 ]) == der_len); +return 0 ; +_error: +rte_free (v); +rte_free (n); +rte_free (e); +rte_free (d); +rte_free (p); +rte_free (q); +rte_free (dp); +rte_free (dq); +rte_free (qinv); +return len; +} + +static int +transform_rsa_param (struct rte_crypto_asym_xform *xform, +VhostUserCryptoAsymSessionParam *param) +{ +int ret = -EINVAL ; + + ret =virtio_crypto_asym_rsa_der_to_xform (param->key_buf, param->key_len, xform); +if (ret <0 ) + goto _error; + +switch (param->u.rsa.padding_algo) { +case VIRTIO_CRYPTO_RSA_RAW_PADDING : + xform->rsa.padding.type =RTE_CRYPTO_RSA_PADDING_NONE ; +break ; +case VIRTIO_CRYPTO_RSA_PKCS1_PADDING : + xform->rsa.padding.type =RTE_CRYPTO_RSA_PADDING_PKCS1_5 ; +break ; +default : +VC_LOG_ERR ("Unknown padding type" ); + goto _error; + } + + xform->rsa.key_type =RTE_RSA_KEY_TYPE_QT ; + xform->xform_type =RTE_CRYPTO_ASYM_XFORM_RSA ; +_error: +return ret; +} + +static void +vhost_crypto_create_asym_sess (struct vhost_crypto *vcrypto, +VhostUserCryptoSessionParam *sess_param) +{ +struct rte_cryptodev_asym_session *session =NULL ; +struct vhost_crypto_session *vhost_session; +struct rte_crypto_asym_xform xform = {0 }; +int ret; + +switch (sess_param->u.asym_sess.algo) { +case VIRTIO_CRYPTO_AKCIPHER_RSA : + ret =transform_rsa_param (&xform, &sess_param->u.asym_sess); +if (unlikely (ret)) { +VC_LOG_ERR ("Error transform session msg (%i)" , ret); + sess_param->session_id = ret; +return ; + } +break ; +default : +VC_LOG_ERR ("Invalid op algo" ); + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +return ; + } + + ret =rte_cryptodev_asym_session_create (vcrypto->cid, &xform, + vcrypto->sess_pool, (void *)&session); +if (!session) { +VC_LOG_ERR ("Failed to create session" ); + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +return ; + } + +/* insert session to map */ + vhost_session =rte_malloc (NULL ,sizeof (*vhost_session),0 ); +if (vhost_session ==NULL ) { +VC_LOG_ERR ("Failed to alloc session memory" ); + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +return ; + } + + vhost_session->type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + vhost_session->asym = session; +if ((rte_hash_add_key_data (vcrypto->session_map, + &vcrypto->last_session_id, vhost_session) <0 )) { +VC_LOG_ERR ("Failed to insert session to hash table" ); + +if (rte_cryptodev_asym_session_free (vcrypto->cid, session) <0 ) +VC_LOG_ERR ("Failed to free session" ); + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +return ; + } + +VC_LOG_INFO ("Session %" PRIu64" created for vdev %i." , + vcrypto->last_session_id, vcrypto->dev->vid); + + sess_param->session_id = vcrypto->last_session_id; + vcrypto->last_session_id++; +} + +static void +vhost_crypto_create_sess (struct vhost_crypto *vcrypto, +VhostUserCryptoSessionParam *sess_param) +{ +if (sess_param->op_code ==VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION ) +vhost_crypto_create_asym_sess (vcrypto, sess_param); +else +vhost_crypto_create_sym_sess (vcrypto, sess_param); +} +static int vhost_crypto_close_sess (struct vhost_crypto *vcrypto,uint64_t session_id) { -struct rte_cryptodev_sym_session *session; +struct rte_cryptodev_asym_session *asym_session =NULL ; +struct rte_cryptodev_sym_session *sym_session =NULL ; +struct vhost_crypto_session *vhost_session =NULL ;uint64_t sess_id = session_id;int ret; ret =rte_hash_lookup_data (vcrypto->session_map, &sess_id, - (void **)&session); - + (void **)&vhost_session);if (unlikely (ret <0 )) { -VC_LOG_ERR ("Failed to delete session %" PRIu64"." , session_id); +VC_LOG_ERR ("Failed to find session for id %" PRIu64"." , session_id); +return -VIRTIO_CRYPTO_INVSESS ; + } + +if (vhost_session->type ==RTE_CRYPTO_OP_TYPE_SYMMETRIC ) { + sym_session = vhost_session->sym; + }else if (vhost_session->type ==RTE_CRYPTO_OP_TYPE_ASYMMETRIC ) { + asym_session = vhost_session->asym; + }else { +VC_LOG_ERR ("Invalid session for id %" PRIu64"." , session_id);return -VIRTIO_CRYPTO_INVSESS ; } -if (rte_cryptodev_sym_session_free (vcrypto->cid, session) <0 ) { +if (sym_session !=NULL && +rte_cryptodev_sym_session_free (vcrypto->cid, sym_session) <0 ) { +VC_LOG_DBG ("Failed to free session" ); +return -VIRTIO_CRYPTO_ERR ; + } + +if (asym_session !=NULL && +rte_cryptodev_asym_session_free (vcrypto->cid, asym_session) <0 ) {VC_LOG_DBG ("Failed to free session" );return -VIRTIO_CRYPTO_ERR ; }
@@ -430,6 +682,7 @@ vhost_crypto_close_sess(struct vhost_crypto *vcrypto, uint64_t session_id)VC_LOG_INFO ("Session %" PRIu64" deleted for vdev %i." , sess_id, vcrypto->dev->vid); +rte_free (vhost_session);return 0 ; }
@@ -1123,6 +1376,118 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,return ret; } +static __rte_always_inline uint8_t +vhost_crypto_check_akcipher_request (struct virtio_crypto_akcipher_data_req *req) +{ +RTE_SET_USED (req); +return VIRTIO_CRYPTO_OK ; +} + +static __rte_always_inline uint8_t +prepare_asym_rsa_op (struct vhost_crypto *vcrypto,struct rte_crypto_op *op, +struct vhost_crypto_data_req *vc_req, +struct virtio_crypto_op_data_req *req, +struct vhost_crypto_desc *head, +uint32_t max_n_descs) +{ +uint8_t ret =vhost_crypto_check_akcipher_request (&req->u.akcipher_req); +struct rte_crypto_rsa_op_param *rsa = &op->asym->rsa; +struct vhost_crypto_desc *desc = head; +uint16_t wlen =0 ; + +if (unlikely (ret !=VIRTIO_CRYPTO_OK )) + goto error_exit; + +/* prepare */ +switch (vcrypto->option) { +case RTE_VHOST_CRYPTO_ZERO_COPY_DISABLE : + vc_req->wb_pool = vcrypto->wb_pool; +if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_SIGN ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_SIGN ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.src_data_len; + rsa->sign.length = req->u.akcipher_req.para.dst_data_len; + wlen = rsa->sign.length; + desc =find_write_desc (head, desc, max_n_descs); +if (unlikely (!desc)) { +VC_LOG_ERR ("Cannot find write location" ); + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + rsa->sign.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RW ); +if (unlikely (rsa->sign.data ==NULL )) { + ret =VIRTIO_CRYPTO_ERR ; + goto error_exit; + } + + desc +=1 ; + }else if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_VERIFY ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_VERIFY ; + rsa->sign.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->sign.length = req->u.akcipher_req.para.src_data_len; + desc +=1 ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.dst_data_len; + desc +=1 ; + }else if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_ENCRYPT ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_ENCRYPT ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.src_data_len; + rsa->cipher.length = req->u.akcipher_req.para.dst_data_len; + wlen = rsa->cipher.length; + desc =find_write_desc (head, desc, max_n_descs); +if (unlikely (!desc)) { +VC_LOG_ERR ("Cannot find write location" ); + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + rsa->cipher.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RW ); +if (unlikely (rsa->cipher.data ==NULL )) { + ret =VIRTIO_CRYPTO_ERR ; + goto error_exit; + } + + desc +=1 ; + }else if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_DECRYPT ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_DECRYPT ; + rsa->cipher.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->cipher.length = req->u.akcipher_req.para.src_data_len; + desc +=1 ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.dst_data_len; + desc +=1 ; + }else { + goto error_exit; + } +break ; +case RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE : +default : + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + op->type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + op->sess_type =RTE_CRYPTO_OP_WITH_SESSION ; + + vc_req->inhdr =get_data_ptr (vc_req, desc,VHOST_ACCESS_WO ); +if (unlikely (vc_req->inhdr ==NULL )) { + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + vc_req->inhdr->status =VIRTIO_CRYPTO_OK ; + vc_req->len = wlen +INHDR_LEN ; +return 0 ; +error_exit: +if (vc_req->wb) +free_wb_data (vc_req->wb, vc_req->wb_pool); + + vc_req->len =INHDR_LEN ; +return ret; +} +/** * Process on descriptor */
@@ -1133,17 +1498,21 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, uint16_t desc_idx) __rte_no_thread_safety_analysis/* FIXME: requires iotlb_lock? */ { -struct vhost_crypto_data_req *vc_req =rte_mbuf_to_priv (op->sym->m_src); -struct rte_cryptodev_sym_session *session; +struct vhost_crypto_data_req *vc_req, *vc_req_out; +struct rte_cryptodev_asym_session *asym_session; +struct rte_cryptodev_sym_session *sym_session; +struct vhost_crypto_session *vhost_session; +struct vhost_crypto_desc *desc = descs; +uint32_t nb_descs =0 , max_n_descs, i; +struct vhost_crypto_data_req data_req;struct virtio_crypto_op_data_req req;struct virtio_crypto_inhdr *inhdr; -struct vhost_crypto_desc *desc = descs;struct vring_desc *src_desc;uint64_t session_id;uint64_t dlen; -uint32_t nb_descs =0 , max_n_descs, i;int err; + vc_req = &data_req; vc_req->desc_idx = desc_idx; vc_req->dev = vcrypto->dev; vc_req->vq = vq;
@@ -1226,12 +1595,14 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto,switch (req.header.opcode) {case VIRTIO_CRYPTO_CIPHER_ENCRYPT :case VIRTIO_CRYPTO_CIPHER_DECRYPT : + vc_req_out =rte_mbuf_to_priv (op->sym->m_src); +rte_memcpy (vc_req_out, vc_req,sizeof (struct vhost_crypto_data_req )); session_id = req.header.session_id;/* one branch to avoid unnecessary table lookup */ -if (vcrypto->cache_session_id != session_id) { +if (vcrypto->cache_sym_session_id != session_id) { err =rte_hash_lookup_data (vcrypto->session_map, - &session_id, (void **)&session); + &session_id, (void **)&vhost_session);if (unlikely (err <0 )) { err =VIRTIO_CRYPTO_ERR ; VC_LOG_ERR("Failed to find session %"PRIu64,
@@ -1239,13 +1610,14 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, goto error_exit; } - vcrypto->cache_session = session; - vcrypto->cache_session_id = session_id; + vcrypto->cache_sym_session = vhost_session->sym; + vcrypto->cache_sym_session_id = session_id; } - session = vcrypto->cache_session; + sym_session = vcrypto->cache_sym_session; + op->type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; - err =rte_crypto_op_attach_sym_session (op, session); + err =rte_crypto_op_attach_sym_session (op, sym_session);if (unlikely (err <0 )) { err =VIRTIO_CRYPTO_ERR ;VC_LOG_ERR ("Failed to attach session to op" );
@@ -1257,12 +1629,12 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, err =VIRTIO_CRYPTO_NOTSUPP ;break ;case VIRTIO_CRYPTO_SYM_OP_CIPHER : - err =prepare_sym_cipher_op (vcrypto, op, vc_req, + err =prepare_sym_cipher_op (vcrypto, op, vc_req_out, &req.u.sym_req.u.cipher, desc, max_n_descs);break ;case VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING : - err =prepare_sym_chain_op (vcrypto, op, vc_req, + err =prepare_sym_chain_op (vcrypto, op, vc_req_out, &req.u.sym_req.u.chain, desc, max_n_descs);break ;
@@ -1271,6 +1643,53 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto,VC_LOG_ERR ("Failed to process sym request" ); goto error_exit; } +break ; +case VIRTIO_CRYPTO_AKCIPHER_SIGN : +case VIRTIO_CRYPTO_AKCIPHER_VERIFY : +case VIRTIO_CRYPTO_AKCIPHER_ENCRYPT : +case VIRTIO_CRYPTO_AKCIPHER_DECRYPT : + session_id = req.header.session_id; + +/* one branch to avoid unnecessary table lookup */ +if (vcrypto->cache_asym_session_id != session_id) { + err =rte_hash_lookup_data (vcrypto->session_map, + &session_id, (void **)&vhost_session); +if (unlikely (err <0 )) { + err =VIRTIO_CRYPTO_ERR ; +VC_LOG_ERR ("Failed to find asym session %" PRIu64, + session_id); + goto error_exit; + } + + vcrypto->cache_asym_session = vhost_session->asym; + vcrypto->cache_asym_session_id = session_id; + } + + asym_session = vcrypto->cache_asym_session; + op->type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + + err =rte_crypto_op_attach_asym_session (op, asym_session); +if (unlikely (err <0 )) { + err =VIRTIO_CRYPTO_ERR ; +VC_LOG_ERR ("Failed to attach asym session to op" ); + goto error_exit; + } + + vc_req_out =rte_cryptodev_asym_session_get_user_data (asym_session); +rte_memcpy (vc_req_out, vc_req,sizeof (struct vhost_crypto_data_req )); + vc_req_out->wb =NULL ; + +switch (req.header.algo) { +case VIRTIO_CRYPTO_AKCIPHER_RSA : + err =prepare_asym_rsa_op (vcrypto, op, vc_req_out, + &req, desc, max_n_descs); +break ; + } +if (unlikely (err !=0 )) { +VC_LOG_ERR ("Failed to process asym request" ); + goto error_exit; + } +break ;default : err =VIRTIO_CRYPTO_ERR ;
@@ -1294,12 +1713,22 @@ static __rte_always_inline struct vhost_virtqueue * vhost_crypto_finalize_one_request(struct rte_crypto_op *op, struct vhost_virtqueue *old_vq) { - struct rte_mbuf *m_src = op->sym->m_src; -struct rte_mbuf *m_dst = op->sym->m_dst; -struct vhost_crypto_data_req *vc_req =rte_mbuf_to_priv (m_src); + struct rte_mbuf *m_src = NULL, *m_dst = NULL; +struct vhost_crypto_data_req *vc_req;struct vhost_virtqueue *vq;uint16_t used_idx, desc_idx; +if (op->type ==RTE_CRYPTO_OP_TYPE_SYMMETRIC ) { + m_src = op->sym->m_src; + m_dst = op->sym->m_dst; + vc_req =rte_mbuf_to_priv (m_src); + }else if (op->type ==RTE_CRYPTO_OP_TYPE_ASYMMETRIC ) { + vc_req =rte_cryptodev_asym_session_get_user_data (op->asym->session); + }else { +VC_LOG_ERR ("Invalid crypto op type" ); +return NULL ; + } +if (unlikely (!vc_req)) {VC_LOG_ERR ("Failed to retrieve vc_req" );return NULL ;
@@ -1321,10 +1750,11 @@ vhost_crypto_finalize_one_request(struct rte_crypto_op *op, vq->used->ring[desc_idx].id = vq->avail->ring[desc_idx]; vq->used->ring[desc_idx].len = vc_req->len; -rte_mempool_put (m_src->pool, (void *)m_src); - -if (m_dst) -rte_mempool_put (m_dst->pool, (void *)m_dst); +if (op->type ==RTE_CRYPTO_OP_TYPE_SYMMETRIC ) { +rte_mempool_put (m_src->pool, (void *)m_src); +if (m_dst) +rte_mempool_put (m_dst->pool, (void *)m_dst); + }return vc_req->vq; }
@@ -1407,8 +1837,9 @@ rte_vhost_crypto_create(int vid, uint8_t cryptodev_id, vcrypto->sess_pool = sess_pool; vcrypto->cid = cryptodev_id; - vcrypto->cache_session_id =UINT64_MAX ; - vcrypto->last_session_id =1 ; + vcrypto->cache_sym_session_id =UINT64_MAX ; + vcrypto->cache_asym_session_id =UINT64_MAX ; + vcrypto->last_session_id =0 ; vcrypto->dev = dev; vcrypto->option =RTE_VHOST_CRYPTO_ZERO_COPY_DISABLE ;
@@ -1580,6 +2011,9 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, vq = dev->virtqueue[qid]; +if (!vq || !vq->avail) +return 0 ; + avail_idx = *((volatile uint16_t *)&vq->avail->idx); start_idx = vq->last_used_idx; count = avail_idx - start_idx;
lib/vhost/vhost_user.h +29 -4
@@ -99,11 +99,10 @@ typedef struct VhostUserLog {/* Comply with Cryptodev-Linux */ #define VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH 512#define VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH 64 +#define VHOST_USER_CRYPTO_MAX_KEY_LENGTH 1024/* Same structure as vhost-user backend session info */ -typedef struct VhostUserCryptoSessionParam { - int64_t session_id; - uint32_t op_code; +typedef struct VhostUserCryptoSymSessionParam { uint32_t cipher_algo; uint32_t cipher_key_len; uint32_t hash_algo;
@@ -114,10 +113,36 @@ typedef struct VhostUserCryptoSessionParam {uint8_t dir;uint8_t hash_mode;uint8_t chaining_dir; -uint8_t *ciphe_key; +uint8_t *cipher_key;uint8_t *auth_key;uint8_t cipher_key_buf[VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH ];uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH ]; +} VhostUserCryptoSymSessionParam; + + +typedef struct VhostUserCryptoAsymRsaParam { +uint32_t padding_algo; +uint32_t hash_algo; +}VhostUserCryptoAsymRsaParam ; + +typedef struct VhostUserCryptoAsymSessionParam { +uint32_t algo; +uint32_t key_type; +uint32_t key_len; +uint8_t *key; +union { +VhostUserCryptoAsymRsaParam rsa; + } u; +uint8_t key_buf[VHOST_USER_CRYPTO_MAX_KEY_LENGTH ]; +}VhostUserCryptoAsymSessionParam ; + +typedef struct VhostUserCryptoSessionParam { +uint32_t op_code; +union { +VhostUserCryptoSymSessionParam sym_sess; +VhostUserCryptoAsymSessionParam asym_sess; + } u; +uint64_t session_id; }VhostUserCryptoSessionParam ; typedef struct VhostUserVringArea {
Signature · 1 line
2.25.1
PATCH 8/16 examples/vhost_crypto: add asymmetric support
In reply to Gowrishankar MuthukrishnanAdd symmetric support.
--- examples/vhost_crypto/main.c | 54 ++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 14 deletions(-)
examples/vhost_crypto/main.c +40 -14
@@ -59,6 +59,7 @@ struct vhost_crypto_options {uint32_t nb_los;uint32_t zero_copy;uint32_t guest_polling; +bool asymmetric_crypto; } options;enum {
@@ -70,6 +71,8 @@ enum {OPT_ZERO_COPY_NUM , #define OPT_POLLING "guest-polling"OPT_POLLING_NUM , +#define OPT_ASYM "asymmetric-crypto" + OPT_ASYM_NUM, };#define NB_SOCKET_FIELDS (2)
@@ -202,9 +205,10 @@ vhost_crypto_usage(const char *prgname)" --%s <lcore>,SOCKET-FILE-PATH\n" " --%s (lcore,cdev_id,queue_id)[,(lcore,cdev_id,queue_id)]\n" " --%s: zero copy\n" -" --%s: guest polling\n" , +" --%s: guest polling\n" +" --%s: asymmetric crypto\n" , prgname,OPT_SOCKET_FILE ,OPT_CONFIG , - OPT_ZERO_COPY, OPT_POLLING); + OPT_ZERO_COPY, OPT_POLLING, OPT_ASYM); } static int
@@ -223,6 +227,8 @@ vhost_crypto_parse_args(int argc, char **argv) NULL, OPT_ZERO_COPY_NUM}, {OPT_POLLING , no_argument, NULL, OPT_POLLING_NUM}, + {OPT_ASYM, no_argument, + NULL, OPT_ASYM_NUM}, {NULL, 0, 0, 0} };
@@ -262,6 +268,10 @@ vhost_crypto_parse_args(int argc, char **argv) options.guest_polling =1 ;break ; +case OPT_ASYM_NUM : + options.asymmetric_crypto = true; +break ; +default :vhost_crypto_usage (prgname);return -EINVAL ;
@@ -362,8 +372,8 @@ destroy_device(int vid) }static const struct rte_vhost_device_ops virtio_crypto_device_ops = { - .new_device = new_device, - .destroy_device = destroy_device, + .new_connection = new_device, + .destroy_connection = destroy_device, }; static int
@@ -376,6 +386,7 @@ vhost_crypto_worker(void *arg)int callfds[VIRTIO_CRYPTO_MAX_NUM_BURST_VQS ];uint32_t lcore_id =rte_lcore_id ();uint32_t burst_size =MAX_PKT_BURST ; +enum rte_crypto_op_type cop_type;uint32_t i, j, k;uint32_t to_fetch, fetched;
@@ -383,9 +394,13 @@ vhost_crypto_worker(void *arg)RTE_LOG (INFO ,USER1 ,"Processing on Core %u started\n" , lcore_id); + cop_type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; +if (options.asymmetric_crypto) + cop_type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; +for (i =0 ; i <NB_VIRTIO_QUEUES ; i++) {if (rte_crypto_op_bulk_alloc (info->cop_pool, -RTE_CRYPTO_OP_TYPE_SYMMETRIC , ops[i], + cop_type, ops[i], burst_size) < burst_size) {RTE_LOG (ERR ,USER1 ,"Failed to alloc cops\n" ); ret =-1 ;
@@ -411,12 +426,11 @@ vhost_crypto_worker(void *arg) fetched);if (unlikely (rte_crypto_op_bulk_alloc ( info->cop_pool, -RTE_CRYPTO_OP_TYPE_SYMMETRIC , + cop_type, ops[j], fetched) < fetched)) {RTE_LOG (ERR ,USER1 ,"Failed realloc\n" );return -1 ; } - fetched = rte_cryptodev_dequeue_burst( info->cid, info->qid, ops_deq[j], RTE_MIN(burst_size,
@@ -477,6 +491,7 @@ main(int argc, char *argv[])struct rte_cryptodev_qp_conf qp_conf;struct rte_cryptodev_config config;struct rte_cryptodev_info dev_info; +enum rte_crypto_op_type cop_type;char name[128 ];uint32_t i, j, lcore;int ret;
@@ -539,12 +554,21 @@ main(int argc, char *argv[]) goto error_exit; } -snprintf (name,127 ,"SESS_POOL_%u" , lo->lcore_id); - info->sess_pool =rte_cryptodev_sym_session_pool_create (name, -SESSION_MAP_ENTRIES , -rte_cryptodev_sym_get_private_session_size ( - info->cid),0 ,0 , -rte_lcore_to_socket_id (lo->lcore_id)); +if (!options.asymmetric_crypto) { +snprintf (name,127 ,"SYM_SESS_POOL_%u" , lo->lcore_id); + info->sess_pool =rte_cryptodev_sym_session_pool_create (name, +SESSION_MAP_ENTRIES , +rte_cryptodev_sym_get_private_session_size ( + info->cid),0 ,0 , +rte_lcore_to_socket_id (lo->lcore_id)); + cop_type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; + }else { +snprintf (name,127 ,"ASYM_SESS_POOL_%u" , lo->lcore_id); + info->sess_pool =rte_cryptodev_asym_session_pool_create (name, +SESSION_MAP_ENTRIES ,0 ,64 , +rte_lcore_to_socket_id (lo->lcore_id)); + cop_type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + }if (!info->sess_pool) {RTE_LOG (ERR ,USER1 ,"Failed to create mempool" );
@@ -553,7 +577,7 @@ main(int argc, char *argv[])snprintf (name,127 ,"COPPOOL_%u" , lo->lcore_id); info->cop_pool =rte_crypto_op_pool_create (name, -RTE_CRYPTO_OP_TYPE_SYMMETRIC ,NB_MEMPOOL_OBJS , + cop_type,NB_MEMPOOL_OBJS ,NB_CACHE_OBJS ,VHOST_CRYPTO_MAX_IV_LEN ,rte_lcore_to_socket_id (lo->lcore_id));
@@ -567,6 +591,8 @@ main(int argc, char *argv[]) qp_conf.nb_descriptors =NB_CRYPTO_DESCRIPTORS ; qp_conf.mp_session = info->sess_pool; +if (options.asymmetric_crypto) + qp_conf.mp_session =NULL ;for (j =0 ; j < dev_info.max_nb_queue_pairs; j++) { ret = rte_cryptodev_queue_pair_setup(info->cid, j,
Signature · 1 line
2.25.1
PATCH 9/16 crypto/virtio: fix dataqueues iteration
In reply to Gowrishankar MuthukrishnanFix dataqueues iteration using nb_queue_pairs info available in device data instead of max dataqueues as dataqueue count might have been changed in device configuration.
--- drivers/crypto/virtio/virtio_cryptodev.c | 3 +-- drivers/crypto/virtio/virtio_rxtx.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +1 -2
@@ -863,9 +863,8 @@ static void virtio_crypto_dev_free_mbufs(struct rte_cryptodev *dev) {uint32_t i; -struct virtio_crypto_hw *hw = dev->data->dev_private; -for (i =0 ; i < hw->max_dataqueues; i++) { +for (i =0 ; i < dev->data->nb_queue_pairs; i++) {VIRTIO_CRYPTO_INIT_LOG_DBG ("Before freeing dataq[%d] used " "and unused buf" , i); VIRTQUEUE_DUMP((struct virtqueue *)
drivers/crypto/virtio/virtio_rxtx.c +1 -2
@@ -612,12 +612,11 @@ virtio_crypto_dataq_start(struct rte_cryptodev *dev)* - Setup vring structure for data queues */ uint16_t i; -struct virtio_crypto_hw *hw = dev->data->dev_private;PMD_INIT_FUNC_TRACE ();/* Start data vring. */ -for (i =0 ; i < hw->max_dataqueues; i++) { +for (i =0 ; i < dev->data->nb_queue_pairs; i++) {virtio_crypto_vring_start (dev->data->queue_pairs[i]);VIRTQUEUE_DUMP ((struct virtqueue *)dev->data->queue_pairs[i]); }
Signature · 1 line
2.25.1
PATCH 10/16 crypto/virtio: refactor queue operations
In reply to Gowrishankar MuthukrishnanMove existing control queue operations into a common place that would be shared with other virtio type of devices.
--- drivers/crypto/virtio/meson.build | 1 + drivers/crypto/virtio/virtio_crypto_algs.h | 2 +- drivers/crypto/virtio/virtio_cryptodev.c | 573 +++++++++------------ drivers/crypto/virtio/virtio_cvq.c | 130 +++++ drivers/crypto/virtio/virtio_cvq.h | 33 ++ drivers/crypto/virtio/virtio_pci.h | 6 +- drivers/crypto/virtio/virtio_ring.h | 12 +- drivers/crypto/virtio/virtio_rxtx.c | 42 +- drivers/crypto/virtio/virtio_rxtx.h | 13 + drivers/crypto/virtio/virtqueue.c | 191 ++++++- drivers/crypto/virtio/virtqueue.h | 89 +++- 11 files changed, 706 insertions(+), 386 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_cvq.c create mode 100644 drivers/crypto/virtio/virtio_cvq.h create mode 100644 drivers/crypto/virtio/virtio_rxtx.h
drivers/crypto/virtio/meson.build +1 -0
@@ -11,6 +11,7 @@ includes += include_directories('../../../lib/vhost') deps += 'bus_pci' sources = files( 'virtio_cryptodev.c', + 'virtio_cvq.c', 'virtio_pci.c', 'virtio_rxtx.c', 'virtqueue.c',
drivers/crypto/virtio/virtio_crypto_algs.h +1 -1
@@ -22,7 +22,7 @@ struct virtio_crypto_session { phys_addr_t phys_addr; } aad; -struct virtio_crypto_op_ctrl_req ctrl; +struct virtio_pmd_ctrl ctrl; };#endif /* _VIRTIO_CRYPTO_ALGS_H_ */
drivers/crypto/virtio/virtio_cryptodev.c +231 -342
776 lines not on this page · raw message
drivers/crypto/virtio/virtio_cvq.c new file +130 -0
130 lines not on this page · raw message
drivers/crypto/virtio/virtio_cvq.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2024 Marvell +*/ + +#ifndef _VIRTIO_CVQ_H_ +#define _VIRTIO_CVQ_H_ + +#include <rte_spinlock.h> +#include <virtio_crypto.h> + +struct virtqueue ; + +struct virtcrypto_ctl { +const struct rte_memzone *hdr_mz;/**< memzone to populate hdr. */ +rte_iova_t hdr_mem;/**< hdr for each xmit packet */ +rte_spinlock_t lock;/**< spinlock for control queue. */ +void (*notify_queue)(struct virtqueue *vq,void *cookie);/**< notify ops. */ +void *notify_cookie;/**< cookie for notify ops */ +}; + +#define VIRTIO_MAX_CTRL_DATA 2048 + +struct virtio_pmd_ctrl { +struct virtio_crypto_op_ctrl_req hdr; +struct virtio_crypto_session_input input; +uint8_t data[VIRTIO_MAX_CTRL_DATA ]; +}; + +int +virtio_crypto_send_command (struct virtcrypto_ctl *cvq,struct virtio_pmd_ctrl *ctrl, +int *dlen,int pkt_num); + +#endif /* _VIRTIO_CVQ_H_ */
drivers/crypto/virtio/virtio_pci.h +4 -2
@@ -176,8 +176,7 @@ struct virtio_pci_ops { };struct virtio_crypto_hw { -/* control queue */ -struct virtqueue *cvq; +struct virtqueue **vqs;uint16_t dev_id;uint16_t max_dataqueues;uint64_t req_guest_features;
@@ -190,6 +189,9 @@ struct virtio_crypto_hw {struct virtio_pci_common_cfg *common_cfg;struct virtio_crypto_config *dev_cfg;const struct rte_cryptodev_capabilities *virtio_dev_capabilities; +uint8_t weak_barriers; +struct virtcrypto_ctl *cvq; +bool use_va; };/*
drivers/crypto/virtio/virtio_ring.h +10 -2
@@ -59,6 +59,7 @@ struct vring_used {struct vring {unsigned int num; +rte_iova_t desc_iova;struct vring_desc *desc;struct vring_avail *avail;struct vring_used *used;
@@ -111,17 +112,24 @@ vring_size(unsigned int num, unsigned long align) }static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p, -unsigned long align) +vring_init_split (struct vring *vr,uint8_t *p,rte_iova_t iova, +unsigned long align,unsigned int num) { vr->num = num; vr->desc = (struct vring_desc *) p; + vr->desc_iova = iova; vr->avail = (struct vring_avail *) (p + num *sizeof (struct vring_desc )); vr->used = (void *)RTE_ALIGN_CEIL ((uintptr_t )(&vr->avail->ring[num]), align); } +static inline void +vring_init (struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) +{ +vring_init_split (vr, p,0 , align, num); +} +/* * The following is used with VIRTIO_RING_F_EVENT_IDX. * Assuming a given event_idx value from the other size, if we have
drivers/crypto/virtio/virtio_rxtx.c +16 -26
111 lines not on this page · raw message
drivers/crypto/virtio/virtio_rxtx.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2024 Marvell. +*/ + +#ifndef _VIRTIO_RXTX_H_ +#define _VIRTIO_RXTX_H_ + +struct virtcrypto_data { +const struct rte_memzone *hdr_mz;/**< memzone to populate hdr. */ +rte_iova_t hdr_mem;/**< hdr for each xmit packet */ +}; + +#endif /* _VIRTIO_RXTX_H_ */
drivers/crypto/virtio/virtqueue.c +188 -3
212 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h +79 -10
162 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 11/16 crypto/virtio: add packed ring support
In reply to Gowrishankar MuthukrishnanAdd packed ring support.
--- drivers/crypto/virtio/virtio_cryptodev.c | 125 +++++++ drivers/crypto/virtio/virtio_cryptodev.h | 13 +- drivers/crypto/virtio/virtio_cvq.c | 103 +++++- drivers/crypto/virtio/virtio_pci.h | 25 ++ drivers/crypto/virtio/virtio_ring.h | 59 ++- drivers/crypto/virtio/virtio_rxtx.c | 442 ++++++++++++++++++++++- drivers/crypto/virtio/virtqueue.c | 50 ++- drivers/crypto/virtio/virtqueue.h | 132 ++++++- 8 files changed, 920 insertions(+), 29 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +125 -0
@@ -869,6 +869,125 @@ virtio_crypto_clear_session(rte_free (ctrl); } +static void +virtio_crypto_clear_session_packed ( +struct rte_cryptodev *dev, +struct virtio_crypto_op_ctrl_req *ctrl) +{ +struct virtio_crypto_hw *hw; +struct virtqueue *vq; +struct vring_packed_desc *desc; +uint8_t *status; +uint8_t needed =1 ; +uint32_t head; +uint64_t malloc_phys_addr; +uint8_t len_inhdr =sizeof (struct virtio_crypto_inhdr ); +uint32_t len_op_ctrl_req =sizeof (struct virtio_crypto_op_ctrl_req ); +uint64_t session_id = ctrl->u.destroy_session.session_id; +uint16_t flags; +uint8_t nb_descs =0 ; + + hw = dev->data->dev_private; + vq =virtcrypto_cq_to_vq (hw->cvq); + head = vq->vq_avail_idx; + flags = vq->vq_packed.cached_flags; + +VIRTIO_CRYPTO_SESSION_LOG_INFO ("vq->vq_desc_head_idx = %d, " +"vq = %p" , vq->vq_desc_head_idx, vq); + +if (vq->vq_free_cnt < needed) { +VIRTIO_CRYPTO_SESSION_LOG_ERR ( +"vq->vq_free_cnt = %d is less than %d, " +"not enough" , vq->vq_free_cnt, needed); +return ; + } + + malloc_phys_addr =rte_malloc_virt2iova (ctrl); + +/* status part */ + status = &(((struct virtio_crypto_inhdr *) + ((uint8_t *)ctrl + len_op_ctrl_req))->status); + *status =VIRTIO_CRYPTO_ERR ; + +/* indirect desc vring part */ + desc = vq->vq_packed.ring.desc; + +/* ctrl request part */ + desc[head].addr = malloc_phys_addr; + desc[head].len = len_op_ctrl_req; + desc[head].flags =VRING_DESC_F_NEXT | vq->vq_packed.cached_flags; + vq->vq_free_cnt--; + nb_descs++; +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^=VRING_PACKED_DESC_F_AVAIL_USED ; + } + +/* status part */ + desc[vq->vq_avail_idx].addr = malloc_phys_addr + len_op_ctrl_req; + desc[vq->vq_avail_idx].len = len_inhdr; + desc[vq->vq_avail_idx].flags =VRING_DESC_F_WRITE ; + vq->vq_free_cnt--; + nb_descs++; +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^=VRING_PACKED_DESC_F_AVAIL_USED ; + } + +virtqueue_store_flags_packed (&desc[head],VRING_DESC_F_NEXT | flags, + vq->hw->weak_barriers); + +virtio_wmb (vq->hw->weak_barriers); +virtqueue_notify (vq); + +/* wait for used desc in virtqueue +* desc_is_used has a load-acquire or rte_io_rmb inside +*/ +rte_rmb (); +while (!desc_is_used (&desc[head], vq)) { +rte_rmb (); +usleep (100 ); + } + +/* now get used descriptors */ + vq->vq_free_cnt += nb_descs; + vq->vq_used_cons_idx += nb_descs; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +PMD_INIT_LOG (DEBUG ,"vq->vq_free_cnt=%d " +"vq->vq_queue_idx=%d " +"vq->vq_avail_idx=%d " +"vq->vq_used_cons_idx=%d " +"vq->vq_packed.cached_flags=0x%x " +"vq->vq_packed.used_wrap_counter=%d" , + vq->vq_free_cnt, + vq->vq_queue_index, + vq->vq_avail_idx, + vq->vq_used_cons_idx, + vq->vq_packed.cached_flags, + vq->vq_packed.used_wrap_counter); + +if (*status !=VIRTIO_CRYPTO_OK ) { +VIRTIO_CRYPTO_SESSION_LOG_ERR ("Close session failed " +"status=%" PRIu32", session_id=%" PRIu64"" , + *status, session_id); +rte_free (ctrl); +return ; + } + +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_free_cnt=%d " +"vq->vq_desc_head_idx=%d" , + vq->vq_free_cnt, vq->vq_desc_head_idx); + +VIRTIO_CRYPTO_SESSION_LOG_INFO ("Close session %" PRIu64" successfully " , + session_id); + +rte_free (ctrl); +} + static void virtio_crypto_sym_clear_session( struct rte_cryptodev *dev,
@@ -906,6 +1025,9 @@ virtio_crypto_sym_clear_session( ctrl->header.queue_id =0 ; ctrl->u.destroy_session.session_id = session->session_id; +if (vtpci_with_packed_queue (dev->data->dev_private)) +return virtio_crypto_clear_session_packed (dev, ctrl); +return virtio_crypto_clear_session (dev, ctrl); }
@@ -943,6 +1065,9 @@ virtio_crypto_asym_clear_session( ctrl->header.queue_id =0 ; ctrl->u.destroy_session.session_id = session->session_id; +if (vtpci_with_packed_queue (dev->data->dev_private)) +return virtio_crypto_clear_session_packed (dev, ctrl); +return virtio_crypto_clear_session (dev, ctrl); }
drivers/crypto/virtio/virtio_cryptodev.h +12 -1
@@ -10,13 +10,21 @@#include "virtio_ring.h" /* Features desired/implemented by this driver. */ -#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1) +#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1 | \ + 1ULL << VIRTIO_F_IN_ORDER | \ + 1ULL << VIRTIO_F_RING_PACKED | \ + 1ULL << VIRTIO_F_NOTIFICATION_DATA | \ + 1ULL << VIRTIO_RING_F_INDIRECT_DESC | \ + 1ULL << VIRTIO_F_ORDER_PLATFORM)#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7#define VIRTIO_CRYPTO_MAX_IV_SIZE 16 +#define VIRTIO_CRYPTO_MAX_MSG_SIZE 512 +#define VIRTIO_CRYPTO_MAX_SIGN_SIZE 512 +#define VIRTIO_CRYPTO_MAX_CIPHER_SIZE 1024#define VIRTIO_CRYPTO_MAX_KEY_SIZE 256
@@ -34,6 +42,9 @@ struct virtio_crypto_op_cookie {struct virtio_crypto_inhdr inhdr;struct vring_desc desc[NUM_ENTRY_VIRTIO_CRYPTO_OP ];uint8_t iv[VIRTIO_CRYPTO_MAX_IV_SIZE ]; +uint8_t message[VIRTIO_CRYPTO_MAX_MSG_SIZE ]; +uint8_t sign[VIRTIO_CRYPTO_MAX_SIGN_SIZE ]; +uint8_t cipher[VIRTIO_CRYPTO_MAX_CIPHER_SIZE ]; };/*
drivers/crypto/virtio/virtio_cvq.c +101 -2
115 lines not on this page · raw message
drivers/crypto/virtio/virtio_pci.h +25 -0
@@ -83,6 +83,25 @@ struct virtqueue;#define VIRTIO_F_VERSION_1 32#define VIRTIO_F_IOMMU_PLATFORM 33 +#define VIRTIO_F_RING_PACKED 34 + +/* +* Inorder feature indicates that all buffers are used by the device +* in the same order in which they have been made available. +*/ +#define VIRTIO_F_IN_ORDER 35 + +/* +* This feature indicates that memory accesses by the driver and the device +* are ordered in a way described by the platform. +*/ +#define VIRTIO_F_ORDER_PLATFORM 36 + +/* +* This feature indicates that the driver passes extra data (besides +* identifying the virtqueue) in its device notifications. +*/ +#define VIRTIO_F_NOTIFICATION_DATA 38/* The Guest publishes the used index for which it expects an interrupt * at the end of the avail ring. Host should ignore the avail->flags field.
@@ -230,6 +249,12 @@ vtpci_with_feature(struct virtio_crypto_hw *hw, uint64_t bit)return (hw->guest_features & (1ULL << bit)) !=0 ; } +static inline int +vtpci_with_packed_queue (struct virtio_crypto_hw *hw) +{ +return vtpci_with_feature (hw,VIRTIO_F_RING_PACKED ); +} +/* * Function declaration from virtio_pci.c */
drivers/crypto/virtio/virtio_ring.h +58 -1
86 lines not on this page · raw message
drivers/crypto/virtio/virtio_rxtx.c +430 -12
495 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.c +42 -8
84 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h +127 -5
167 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 12/16 common/virtio: common virtio log
In reply to Gowrishankar MuthukrishnanCommon virtio log include file.
---
drivers/{net => common}/virtio/virtio_logs.h | 16 ++--------
drivers/crypto/virtio/meson.build | 1 +
.../{virtio_logs.h => virtio_crypto_logs.h} | 30 ++++++++-----------
drivers/crypto/virtio/virtio_cryptodev.c | 4 +--
drivers/crypto/virtio/virtqueue.h | 2 +-
drivers/net/virtio/meson.build | 3 +-
drivers/net/virtio/virtio.c | 3 +-
drivers/net/virtio/virtio_ethdev.c | 3 +-
drivers/net/virtio/virtio_net_logs.h | 30 +++++++++++++++++++
drivers/net/virtio/virtio_pci.c | 3 +-
drivers/net/virtio/virtio_pci_ethdev.c | 3 +-
drivers/net/virtio/virtio_rxtx.c | 3 +-
drivers/net/virtio/virtio_rxtx_packed.c | 3 +-
drivers/net/virtio/virtio_rxtx_packed.h | 3 +-
drivers/net/virtio/virtio_rxtx_packed_avx.h | 3 +-
drivers/net/virtio/virtio_rxtx_simple.h | 3 +-
.../net/virtio/virtio_user/vhost_kernel_tap.c | 3 +-
drivers/net/virtio/virtio_user/vhost_vdpa.c | 3 +-
drivers/net/virtio/virtio_user_ethdev.c | 3 +-
drivers/net/virtio/virtqueue.c | 3 +-
drivers/net/virtio/virtqueue.h | 3 +-
21 files changed, 77 insertions(+), 51 deletions(-)
rename drivers/{net => common}/virtio/virtio_logs.h (61%)
rename drivers/crypto/virtio/{virtio_logs.h => virtio_crypto_logs.h} (74%)
create mode 100644 drivers/net/virtio/virtio_net_logs.hdrivers/common/virtio/virtio_logs.h renamed from drivers/net/virtio/virtio_logs.h +2 -14
@@ -5,6 +5,8 @@#ifndef _VIRTIO_LOGS_H_#define _VIRTIO_LOGS_H_ +#include <inttypes.h> +#include <rte_log.h> extern int virtio_logtype_init;
@@ -14,20 +16,6 @@ extern int virtio_logtype_init;#define PMD_INIT_FUNC_TRACE () PMD_INIT_LOG(DEBUG, " >>") -#ifdef RTE_LIBRTE_VIRTIO_DEBUG_RX -#define PMD_RX_LOG (level, ...) \ - RTE_LOG_LINE_PREFIX(level, VIRTIO_DRIVER, "%s() rx: ", __func__, __VA_ARGS__) -#else -#define PMD_RX_LOG (...) do { } while(0) -#endif - -#ifdef RTE_LIBRTE_VIRTIO_DEBUG_TX -#define PMD_TX_LOG (level, ...) \ - RTE_LOG_LINE_PREFIX(level, VIRTIO_DRIVER, "%s() tx: ", __func__, __VA_ARGS__) -#else -#define PMD_TX_LOG (...) do { } while(0) -#endif -extern int virtio_logtype_driver;#define RTE_LOGTYPE_VIRTIO_DRIVER virtio_logtype_driver#define PMD_DRV_LOG (level, ...) \
drivers/crypto/virtio/meson.build +1 -0
@@ -8,6 +8,7 @@ if is_windows endif includes += include_directories('../../../lib/vhost') +includes += include_directories('../../common/virtio') deps += 'bus_pci' sources = files( 'virtio_cryptodev.c',
drivers/crypto/virtio/virtio_crypto_logs.h renamed from drivers/crypto/virtio/virtio_logs.h +12 -18
@@ -2,24 +2,18 @@* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. */ -#ifndef _VIRTIO_LOGS_H_ -#define _VIRTIO_LOGS_H_ +#ifndef _VIRTIO_CRYPTO_LOGS_H_ +#define _VIRTIO_CRYPTO_LOGS_H_#include <rte_log.h> -extern int virtio_crypto_logtype_init; -#define RTE_LOGTYPE_VIRTIO_CRYPTO_INIT virtio_crypto_logtype_init +#include "virtio_logs.h" -#define PMD_INIT_LOG (level, ...) \ - RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_INIT, "%s(): ", __func__, __VA_ARGS__) +extern int virtio_logtype_init; -#define PMD_INIT_FUNC_TRACE () PMD_INIT_LOG(DEBUG, " >>") - -extern int virtio_crypto_logtype_init; -#define RTE_LOGTYPE_VIRTIO_CRYPTO_INIT virtio_crypto_logtype_init - -#define VIRTIO_CRYPTO_INIT_LOG_IMPL (level, ...) \ - RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_INIT, "%s(): ", __func__, __VA_ARGS__) +#define VIRTIO_CRYPTO_INIT_LOG_IMPL(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, virtio_logtype_init, \ + "INIT: %s(): " fmt "\n", __func__, ##args)#define VIRTIO_CRYPTO_INIT_LOG_INFO (fmt, ...) \ VIRTIO_CRYPTO_INIT_LOG_IMPL(INFO, fmt, ## __VA_ARGS__)
@@ -75,11 +69,11 @@ extern int virtio_crypto_logtype_tx;#define VIRTIO_CRYPTO_TX_LOG_ERR (fmt, ...) \ VIRTIO_CRYPTO_TX_LOG_IMPL(ERR, fmt, ## __VA_ARGS__) -extern int virtio_crypto_logtype_driver; -#define RTE_LOGTYPE_VIRTIO_CRYPTO_DRIVER virtio_crypto_logtype_driver +extern int virtio_logtype_driver; -#define VIRTIO_CRYPTO_DRV_LOG_IMPL (level, ...) \ - RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_DRIVER, "%s(): ", __func__, __VA_ARGS__) +#define VIRTIO_CRYPTO_DRV_LOG_IMPL(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, virtio_logtype_driver, \ + "DRIVER: %s(): " fmt "\n", __func__, ##args)#define VIRTIO_CRYPTO_DRV_LOG_INFO (fmt, ...) \ VIRTIO_CRYPTO_DRV_LOG_IMPL(INFO, fmt, ## __VA_ARGS__)
@@ -90,4 +84,4 @@ extern int virtio_crypto_logtype_driver;#define VIRTIO_CRYPTO_DRV_LOG_ERR (fmt, ...) \ VIRTIO_CRYPTO_DRV_LOG_IMPL(ERR, fmt, ## __VA_ARGS__) -#endif /* _VIRTIO_LOGS_H_ */ +#endif /* _VIRTIO_CRYPTO_LOGS_H_ */
drivers/crypto/virtio/virtio_cryptodev.c +2 -2
@@ -1749,8 +1749,8 @@ RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_VIRTIO_PMD, rte_virtio_crypto_driver);RTE_PMD_REGISTER_CRYPTO_DRIVER (virtio_crypto_drv, rte_virtio_crypto_driver.driver, cryptodev_virtio_driver_id); -RTE_LOG_REGISTER_SUFFIX (virtio_crypto_logtype_init, init,NOTICE ); +RTE_LOG_REGISTER_SUFFIX (virtio_logtype_init, init,NOTICE );RTE_LOG_REGISTER_SUFFIX (virtio_crypto_logtype_session, session,NOTICE );RTE_LOG_REGISTER_SUFFIX (virtio_crypto_logtype_rx, rx,NOTICE );RTE_LOG_REGISTER_SUFFIX (virtio_crypto_logtype_tx, tx,NOTICE ); -RTE_LOG_REGISTER_SUFFIX (virtio_crypto_logtype_driver, driver,NOTICE ); +RTE_LOG_REGISTER_SUFFIX (virtio_logtype_driver, driver,NOTICE );
drivers/crypto/virtio/virtqueue.h +1 -1
@@ -15,7 +15,7 @@#include "virtio_cvq.h" #include "virtio_pci.h" #include "virtio_ring.h" -#include "virtio_logs.h" +#include "virtio_crypto_logs.h" #include "virtio_crypto.h" #include "virtio_rxtx.h"
drivers/net/virtio/meson.build +2 -1
@@ -22,6 +22,7 @@ sources += files( 'virtqueue.c', ) deps += ['kvargs', 'bus_pci'] +includes += include_directories('../../common/virtio') if arch_subdir == 'x86' if cc_has_avx512
@@ -56,5 +57,5 @@ if is_linux 'virtio_user/vhost_user.c', 'virtio_user/vhost_vdpa.c', 'virtio_user/virtio_user_dev.c') - deps += ['bus_vdev'] + deps += ['bus_vdev', 'common_virtio'] endif
drivers/net/virtio/virtio.c +2 -1
@@ -5,8 +5,9 @@#include <unistd.h> +#include "virtio_net_logs.h" +#include "virtio.h" -#include "virtio_logs.h" uint64_t virtio_negotiate_features (struct virtio_hw *hw,uint64_t host_features)
drivers/net/virtio/virtio_ethdev.c +2 -1
@@ -29,9 +29,10 @@#include <rte_cycles.h> #include <rte_kvargs.h> +#include "virtio_net_logs.h" +#include "virtio_ethdev.h" #include "virtio.h" -#include "virtio_logs.h" #include "virtqueue.h" #include "virtio_cvq.h" #include "virtio_rxtx.h"
drivers/net/virtio/virtio_net_logs.h new file +30 -0
@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2010-2014 Intel Corporation +*/ + +#ifndef _VIRTIO_NET_LOGS_H_ +#define _VIRTIO_NET_LOGS_H_ + +#include <inttypes.h> + +#include <rte_log.h> + +#include "virtio_logs.h" + +#define PMD_INIT_FUNC_TRACE () PMD_INIT_LOG(DEBUG, " >>") + +#ifdef RTE_LIBRTE_VIRTIO_DEBUG_RX +#define PMD_RX_LOG(level, fmt, args...) \ + RTE_LOG(level, VIRTIO_DRIVER, "%s() rx: " fmt "\n", __func__, ## args) +#else +#define PMD_RX_LOG(level, fmt, args...) do { } while (0) +#endif + +#ifdef RTE_LIBRTE_VIRTIO_DEBUG_TX +#define PMD_TX_LOG(level, fmt, args...) \ + RTE_LOG(level, VIRTIO_DRIVER, "%s() tx: " fmt "\n", __func__, ## args) +#else +#define PMD_TX_LOG(level, fmt, args...) do { } while (0) +#endif + +#endif /* _VIRTIO_NET_LOGS_H_ */
drivers/net/virtio/virtio_pci.c +2 -1
@@ -11,8 +11,9 @@#include <rte_io.h> #include <bus_driver.h> +#include "virtio_net_logs.h" +#include "virtio_pci.h" -#include "virtio_logs.h" #include "virtqueue.h" /*
drivers/net/virtio/virtio_pci_ethdev.c +2 -1
@@ -19,10 +19,11 @@#include <dev_driver.h> #include <rte_kvargs.h> +#include "virtio_net_logs.h" +#include "virtio.h" #include "virtio_ethdev.h" #include "virtio_pci.h" -#include "virtio_logs.h" /* * The set of PCI devices this driver supports
drivers/net/virtio/virtio_rxtx.c +2 -1
@@ -26,7 +26,8 @@#include <rte_udp.h> #include <rte_tcp.h> -#include "virtio_logs.h" +#include "virtio_net_logs.h" +#include "virtio_ethdev.h" #include "virtio.h" #include "virtqueue.h"
drivers/net/virtio/virtio_rxtx_packed.c +2 -1
@@ -10,7 +10,8 @@#include <rte_net.h> -#include "virtio_logs.h" +#include "virtio_net_logs.h" +#include "virtio_ethdev.h" #include "virtio_pci.h" #include "virtio_rxtx_packed.h"
drivers/net/virtio/virtio_rxtx_packed.h +2 -1
@@ -13,7 +13,8 @@#include <rte_net.h> -#include "virtio_logs.h" +#include "virtio_net_logs.h" +#include "virtio_ethdev.h" #include "virtio.h" #include "virtqueue.h"
drivers/net/virtio/virtio_rxtx_packed_avx.h +2 -1
@@ -10,7 +10,8 @@#include <rte_net.h> -#include "virtio_logs.h" +#include "virtio_net_logs.h" +#include "virtio_ethdev.h" #include "virtio.h" #include "virtio_rxtx_packed.h"
drivers/net/virtio/virtio_rxtx_simple.h +2 -1
@@ -7,7 +7,8 @@#include <stdint.h> -#include "virtio_logs.h" +#include "virtio_net_logs.h" +#include "virtio_ethdev.h" #include "virtqueue.h" #include "virtio_rxtx.h"
drivers/net/virtio/virtio_user/vhost_kernel_tap.c +2 -1
@@ -14,8 +14,9 @@#include <rte_ether.h> +#include "virtio_net_logs.h" +#include "vhost_kernel_tap.h" -#include "../virtio_logs.h" #include "../virtio.h"
drivers/net/virtio/virtio_user/vhost_vdpa.c +1 -2
@@ -12,8 +12,7 @@#include <rte_memory.h> -#include "vhost.h" -#include "virtio_user_dev.h" +#include "../virtio_net_logs.h" struct vhost_vdpa_data {int vhostfd;
drivers/net/virtio/virtio_user_ethdev.c +2 -1
@@ -20,8 +20,9 @@#include <rte_cycles.h> #include <rte_io.h> +#include "virtio_net_logs.h" +#include "virtio_ethdev.h" -#include "virtio_logs.h" #include "virtio.h" #include "virtqueue.h" #include "virtio_rxtx.h"
drivers/net/virtio/virtqueue.c +2 -1
@@ -9,8 +9,9 @@#include <rte_mbuf.h> #include <rte_memzone.h> +#include "virtio_net_logs.h" +#include "virtqueue.h" -#include "virtio_logs.h" #include "virtio.h" #include "virtio_rxtx_simple.h"
drivers/net/virtio/virtqueue.h +2 -1
@@ -12,9 +12,10 @@#include <rte_mempool.h> #include <rte_net.h> +#include "virtio_net_logs.h" +#include "virtio.h" #include "virtio_ring.h" -#include "virtio_logs.h" #include "virtio_rxtx.h" #include "virtio_cvq.h"
Signature · 1 line
2.25.1
Re: [v1 12/16] common/virtio: common virtio log
Hello Gowri,
Quoted 2 lines · Gowrishankar Muthukrishnan
Common virtio log include file.
That's really a short commitlog..
What are you trying to achieve?
The net/virtio and crypto/virtio drivers had dedicated logtypes so far, which seems preferable.
I don't see a case when using a single logtype for both net and crypto would help.
Some comments below.
And please run checkpatch.
Quoted 37 lines
Signed-off-by Gowrishankar Muthukrishnan <[email protected]>--- drivers/{net => common}/virtio/virtio_logs.h | 16 ++-------- drivers/crypto/virtio/meson.build | 1 + .../{virtio_logs.h => virtio_crypto_logs.h} | 30 ++++++++----------- drivers/crypto/virtio/virtio_cryptodev.c | 4 +-- drivers/crypto/virtio/virtqueue.h | 2 +- drivers/net/virtio/meson.build | 3 +- drivers/net/virtio/virtio.c | 3 +- drivers/net/virtio/virtio_ethdev.c | 3 +- drivers/net/virtio/virtio_net_logs.h | 30 +++++++++++++++++++ drivers/net/virtio/virtio_pci.c | 3 +- drivers/net/virtio/virtio_pci_ethdev.c | 3 +- drivers/net/virtio/virtio_rxtx.c | 3 +- drivers/net/virtio/virtio_rxtx_packed.c | 3 +- drivers/net/virtio/virtio_rxtx_packed.h | 3 +- drivers/net/virtio/virtio_rxtx_packed_avx.h | 3 +- drivers/net/virtio/virtio_rxtx_simple.h | 3 +- .../net/virtio/virtio_user/vhost_kernel_tap.c | 3 +- drivers/net/virtio/virtio_user/vhost_vdpa.c | 3 +- drivers/net/virtio/virtio_user_ethdev.c | 3 +- drivers/net/virtio/virtqueue.c | 3 +- drivers/net/virtio/virtqueue.h | 3 +- 21 files changed, 77 insertions(+), 51 deletions(-) rename drivers/{net => common}/virtio/virtio_logs.h (61%) rename drivers/crypto/virtio/{virtio_logs.h => virtio_crypto_logs.h} (74%) create mode 100644 drivers/net/virtio/virtio_net_logs.hdrivers/common/virtio/virtio_logs.h renamed from drivers/net/virtio/virtio_logs.h +0
-0
drivers/common/virtio/virtio_logs.h line 9
Quoted 5 lines
drivers/common/virtio/virtio_logs.h renamed from drivers/net/virtio/virtio_logs.h +2
-0@@ -5,6 +5,8 @@#ifndef _VIRTIO_LOGS_H_#define _VIRTIO_LOGS_H_ +#include <inttypes.h> +
?
Seems unrelated.
Quoted 29 lines
drivers/common/virtio/virtio_logs.h renamed from drivers/net/virtio/virtio_logs.h +0
-14#include <rte_log.h> extern int virtio_logtype_init;@@ -14,20 +16,6 @@ extern int virtio_logtype_init;#define PMD_INIT_FUNC_TRACE () PMD_INIT_LOG(DEBUG, " >>") -#ifdef RTE_LIBRTE_VIRTIO_DEBUG_RX -#define PMD_RX_LOG (level, ...) \ - RTE_LOG_LINE_PREFIX(level, VIRTIO_DRIVER, "%s() rx: ", __func__, __VA_ARGS__) -#else -#define PMD_RX_LOG (...) do { } while(0) -#endif - -#ifdef RTE_LIBRTE_VIRTIO_DEBUG_TX -#define PMD_TX_LOG (level, ...) \ - RTE_LOG_LINE_PREFIX(level, VIRTIO_DRIVER, "%s() tx: ", __func__, __VA_ARGS__) -#else -#define PMD_TX_LOG (...) do { } while(0) -#endif -extern int virtio_logtype_driver;#define RTE_LOGTYPE_VIRTIO_DRIVER virtio_logtype_driver#define PMD_DRV_LOG (level, ...) \drivers/crypto/virtio/meson.build +0
-0
drivers/crypto/virtio/meson.build if is_windows · line 11
Quoted 4 lines
drivers/crypto/virtio/meson.build +1
-0@@ -8,6 +8,7 @@ if is_windows endif includes += include_directories('../../../lib/vhost') +includes += include_directories('../../common/virtio')
There are some special cases when a driver can't rely on meson dependencies (like order of subdirs evaluation in drivers/meson.build).
For those special cases, include_directories are used.
But this driver does not seem concerned.
There should be dependencies on vhost and common_virtio instead.
Quoted 29 lines
drivers/crypto/virtio/meson.build +0
-0deps += 'bus_pci' sources = files( 'virtio_cryptodev.c',drivers/crypto/virtio/virtio_crypto_logs.h renamed from drivers/crypto/virtio/virtio_logs.h +4
-6@@ -2,24 +2,18 @@* Copyright(c) 2018 HUAWEI TECHNOLOGIES CO., LTD. */ -#ifndef _VIRTIO_LOGS_H_ -#define _VIRTIO_LOGS_H_ +#ifndef _VIRTIO_CRYPTO_LOGS_H_ +#define _VIRTIO_CRYPTO_LOGS_H_#include <rte_log.h> -extern int virtio_crypto_logtype_init; -#define RTE_LOGTYPE_VIRTIO_CRYPTO_INIT virtio_crypto_logtype_init +#include "virtio_logs.h" -#define PMD_INIT_LOG (level, ...) \ - RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_INIT, "%s(): ", __func__, __VA_ARGS__) +extern int virtio_logtype_init;
drivers/crypto/virtio/virtio_crypto_logs.h line 16
Quoted 10 lines
drivers/crypto/virtio/virtio_crypto_logs.h renamed from drivers/crypto/virtio/virtio_logs.h +3
-7-#define PMD_INIT_FUNC_TRACE () PMD_INIT_LOG(DEBUG, " >>") - -extern int virtio_crypto_logtype_init; -#define RTE_LOGTYPE_VIRTIO_CRYPTO_INIT virtio_crypto_logtype_init - -#define VIRTIO_CRYPTO_INIT_LOG_IMPL (level, ...) \ - RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_INIT, "%s(): ", __func__, __VA_ARGS__) +#define VIRTIO_CRYPTO_INIT_LOG_IMPL(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, virtio_logtype_init, \ + "INIT: %s(): " fmt "\n", __func__, ##args)
Don't add back macros directly calling rte_log(). Afaiu, this hunk should be only redirecting RTE_LOGTYPE_VIRTIO_CRYPTO_INIT to virtio_logtype_init.
Quoted 58 lines
drivers/crypto/virtio/virtio_crypto_logs.h renamed from drivers/crypto/virtio/virtio_logs.h +5
-5#define VIRTIO_CRYPTO_INIT_LOG_INFO (fmt, ...) \ VIRTIO_CRYPTO_INIT_LOG_IMPL(INFO, fmt, ## __VA_ARGS__)@@ -75,11 +69,11 @@ extern int virtio_crypto_logtype_tx;#define VIRTIO_CRYPTO_TX_LOG_ERR (fmt, ...) \ VIRTIO_CRYPTO_TX_LOG_IMPL(ERR, fmt, ## __VA_ARGS__) -extern int virtio_crypto_logtype_driver; -#define RTE_LOGTYPE_VIRTIO_CRYPTO_DRIVER virtio_crypto_logtype_driver +extern int virtio_logtype_driver; -#define VIRTIO_CRYPTO_DRV_LOG_IMPL (level, ...) \ - RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_DRIVER, "%s(): ", __func__, __VA_ARGS__) +#define VIRTIO_CRYPTO_DRV_LOG_IMPL(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, virtio_logtype_driver, \ + "DRIVER: %s(): " fmt "\n", __func__, ##args)#define VIRTIO_CRYPTO_DRV_LOG_INFO (fmt, ...) \ VIRTIO_CRYPTO_DRV_LOG_IMPL(INFO, fmt, ## __VA_ARGS__)@@ -90,4 +84,4 @@ extern int virtio_crypto_logtype_driver;#define VIRTIO_CRYPTO_DRV_LOG_ERR (fmt, ...) \ VIRTIO_CRYPTO_DRV_LOG_IMPL(ERR, fmt, ## __VA_ARGS__) -#endif /* _VIRTIO_LOGS_H_ */ +#endif /* _VIRTIO_CRYPTO_LOGS_H_ */ drivers/crypto/virtio/virtio_cryptodev.c +2
-2@@ -1749,8 +1749,8 @@ RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_VIRTIO_PMD, rte_virtio_crypto_driver);RTE_PMD_REGISTER_CRYPTO_DRIVER (virtio_crypto_drv, rte_virtio_crypto_driver.driver, cryptodev_virtio_driver_id); -RTE_LOG_REGISTER_SUFFIX (virtio_crypto_logtype_init, init,NOTICE ); +RTE_LOG_REGISTER_SUFFIX (virtio_logtype_init, init,NOTICE );RTE_LOG_REGISTER_SUFFIX (virtio_crypto_logtype_session, session,NOTICE );RTE_LOG_REGISTER_SUFFIX (virtio_crypto_logtype_rx, rx,NOTICE );RTE_LOG_REGISTER_SUFFIX (virtio_crypto_logtype_tx, tx,NOTICE ); -RTE_LOG_REGISTER_SUFFIX (virtio_crypto_logtype_driver, driver,NOTICE ); +RTE_LOG_REGISTER_SUFFIX (virtio_logtype_driver, driver,NOTICE );drivers/crypto/virtio/virtqueue.h +1
-1@@ -15,7 +15,7 @@#include "virtio_cvq.h" #include "virtio_pci.h" #include "virtio_ring.h" -#include "virtio_logs.h" +#include "virtio_crypto_logs.h" #include "virtio_crypto.h" #include "virtio_rxtx.h" drivers/net/virtio/meson.build +0
-0
drivers/net/virtio/meson.build sources += files( · line 25
Quoted 4 lines
drivers/net/virtio/meson.build +1
-0@@ -22,6 +22,7 @@ sources += files( 'virtqueue.c', ) deps += ['kvargs', 'bus_pci'] +includes += include_directories('../../common/virtio')
Idem, this is unneeded, as long as there is a meson dependency (like below).
Quoted 55 lines
drivers/net/virtio/meson.build +1
-1if arch_subdir == 'x86' if cc_has_avx512@@ -56,5 +57,5 @@ if is_linux 'virtio_user/vhost_user.c', 'virtio_user/vhost_vdpa.c', 'virtio_user/virtio_user_dev.c') - deps += ['bus_vdev'] + deps += ['bus_vdev', 'common_virtio'] endifdrivers/net/virtio/virtio.c +2
-1@@ -5,8 +5,9 @@#include <unistd.h> +#include "virtio_net_logs.h" +#include "virtio.h" -#include "virtio_logs.h" uint64_t virtio_negotiate_features (struct virtio_hw *hw,uint64_t host_features)drivers/net/virtio/virtio_ethdev.c +2
-1@@ -29,9 +29,10 @@#include <rte_cycles.h> #include <rte_kvargs.h> +#include "virtio_net_logs.h" +#include "virtio_ethdev.h" #include "virtio.h" -#include "virtio_logs.h" #include "virtqueue.h" #include "virtio_cvq.h" #include "virtio_rxtx.h" drivers/net/virtio/virtio_net_logs.h new file +8
-0@@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2010-2014 Intel Corporation +*/ + +#ifndef _VIRTIO_NET_LOGS_H_ +#define _VIRTIO_NET_LOGS_H_ + +#include <inttypes.h>
drivers/net/virtio/virtio_net_logs.h line 18
Quoted 10 lines
drivers/net/virtio/virtio_net_logs.h new file +10
-0+ +#include <rte_log.h> + +#include "virtio_logs.h" + +#define PMD_INIT_FUNC_TRACE () PMD_INIT_LOG(DEBUG, " >>") + +#ifdef RTE_LIBRTE_VIRTIO_DEBUG_RX +#define PMD_RX_LOG(level, fmt, args...) \ + RTE_LOG(level, VIRTIO_DRIVER, "%s() rx: " fmt "\n", __func__, ## args)
Rebase damage.
Quoted 12 lines
drivers/net/virtio/virtio_net_logs.h new file +12
-0+#else +#define PMD_RX_LOG(level, fmt, args...) do { } while (0) +#endif + +#ifdef RTE_LIBRTE_VIRTIO_DEBUG_TX +#define PMD_TX_LOG(level, fmt, args...) \ + RTE_LOG(level, VIRTIO_DRIVER, "%s() tx: " fmt "\n", __func__, ## args) +#else +#define PMD_TX_LOG(level, fmt, args...) do { } while (0) +#endif + +#endif /* _VIRTIO_NET_LOGS_H_ */
Signature · 1 line
David Marchand
RE: [EXTERNAL] Re: [v1 12/16] common/virtio: common virtio log
Hi David,
Quoted 9 lines
Hello Gowri,
Quoted 2 lines · Gowrishankar Muthukrishnan
Common virtio log include file.
That's really a short commitlog..
What are you trying to achieve?
As part of sharing vDPA backend ops implementation between net and crypto (in patch 13/16),
I added this patch, but I got your point. I have removed this patch in newer patch series v2 (that I am sending now).
Thanks for the time reviewing it.
Regards,
Gowrishankar
Quoted 1 line
PATCH 13/16 common/virtio: move vDPA to common directory
In reply to Gowrishankar MuthukrishnanMove vhost-vdpa backend implementation into common folder.
---
drivers/common/virtio/meson.build | 13 +++++++++
drivers/common/virtio/version.map | 9 ++++++
.../virtio/virtio_user/vhost.h | 2 --
.../virtio/virtio_user/vhost_vdpa.c | 29 ++++++++++++++++++-
drivers/crypto/virtio/meson.build | 2 +-
drivers/crypto/virtio/virtio_cryptodev.c | 2 --
drivers/meson.build | 1 +
drivers/net/virtio/meson.build | 1 -
drivers/net/virtio/virtio_ethdev.c | 2 --
drivers/net/virtio/virtio_user/vhost_kernel.c | 4 ++-
drivers/net/virtio/virtio_user/vhost_user.c | 2 +-
.../net/virtio/virtio_user/virtio_user_dev.c | 6 ++--
.../net/virtio/virtio_user/virtio_user_dev.h | 24 ++++++++-------
drivers/net/virtio/virtio_user_ethdev.c | 2 +-
14 files changed, 75 insertions(+), 24 deletions(-)
create mode 100644 drivers/common/virtio/meson.build
create mode 100644 drivers/common/virtio/version.map
rename drivers/{net => common}/virtio/virtio_user/vhost.h (98%)
rename drivers/{net => common}/virtio/virtio_user/vhost_vdpa.c (96%)drivers/common/virtio/meson.build new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2024 Marvell + +if is_windows + build = false + reason = 'not supported on Windows' + subdir_done() +endif + +if is_linux + sources += files('virtio_user/vhost_vdpa.c') + deps += ['bus_vdev'] +endif
drivers/common/virtio/version.map new file +9 -0
@@ -0,0 +1,9 @@ +INTERNAL { + global: + + virtio_ops_vdpa; + virtio_logtype_init; + virtio_logtype_driver; + + local: *; +};
drivers/common/virtio/virtio_user/vhost.h renamed from drivers/net/virtio/virtio_user/vhost.h +0 -2
@@ -11,9 +11,7 @@#include <rte_errno.h> -#include "../virtio.h" #include "../virtio_logs.h" -#include "../virtqueue.h" struct vhost_vring_state {unsigned int index;
drivers/common/virtio/virtio_user/vhost_vdpa.c renamed from drivers/net/virtio/virtio_user/vhost_vdpa.c +28 -1
@@ -12,7 +12,8 @@#include <rte_memory.h> -#include "../virtio_net_logs.h" +#include "vhost.h" +#include "../virtio_logs.h" struct vhost_vdpa_data {int vhostfd;
@@ -99,6 +100,29 @@ vhost_vdpa_ioctl(int fd, uint64_t request, void *arg)return 0 ; } +struct virtio_hw { +struct virtqueue **vqs; +}; + +struct virtio_user_dev { +union { +struct virtio_hw hw; +uint8_t dummy[256 ]; + }; + +void *backend_data; +uint16_t **notify_area; +char path[PATH_MAX ]; +bool hw_cvq; +uint16_t max_queue_pairs; +uint64_t device_features; +bool *qp_enabled; +}; + +#define VIRTIO_NET_F_CTRL_VQ 17 +#define VIRTIO_F_IOMMU_PLATFORM 33 +#define VIRTIO_ID_NETWORK 0x01 +static int vhost_vdpa_set_owner (struct virtio_user_dev *dev) {
@@ -714,3 +738,6 @@ struct virtio_user_backend_ops virtio_ops_vdpa = { .map_notification_area = vhost_vdpa_map_notification_area, .unmap_notification_area = vhost_vdpa_unmap_notification_area, }; + +RTE_LOG_REGISTER_SUFFIX (virtio_logtype_init, init,NOTICE ); +RTE_LOG_REGISTER_SUFFIX (virtio_logtype_driver, driver,NOTICE );
drivers/crypto/virtio/meson.build +1 -1
@@ -9,7 +9,7 @@ endif includes += include_directories('../../../lib/vhost') includes += include_directories('../../common/virtio') -deps += 'bus_pci' +deps += ['bus_pci', 'common_virtio'] sources = files( 'virtio_cryptodev.c', 'virtio_cvq.c',
drivers/crypto/virtio/virtio_cryptodev.c +0 -2
@@ -1749,8 +1749,6 @@ RTE_PMD_REGISTER_PCI(CRYPTODEV_NAME_VIRTIO_PMD, rte_virtio_crypto_driver);RTE_PMD_REGISTER_CRYPTO_DRIVER (virtio_crypto_drv, rte_virtio_crypto_driver.driver, cryptodev_virtio_driver_id); -RTE_LOG_REGISTER_SUFFIX (virtio_logtype_init, init,NOTICE );RTE_LOG_REGISTER_SUFFIX (virtio_crypto_logtype_session, session,NOTICE );RTE_LOG_REGISTER_SUFFIX (virtio_crypto_logtype_rx, rx,NOTICE );RTE_LOG_REGISTER_SUFFIX (virtio_crypto_logtype_tx, tx,NOTICE ); -RTE_LOG_REGISTER_SUFFIX (virtio_logtype_driver, driver,NOTICE );
drivers/meson.build +1 -0
@@ -17,6 +17,7 @@ subdirs = [ 'common/nitrox', # depends on bus. 'common/qat', # depends on bus. 'common/sfc_efx', # depends on bus. + 'common/virtio', # depends on bus. 'mempool', # depends on common and bus. 'dma', # depends on common and bus. 'net', # depends on common, bus, mempool
drivers/net/virtio/meson.build +0 -1
@@ -55,7 +55,6 @@ if is_linux 'virtio_user/vhost_kernel.c', 'virtio_user/vhost_kernel_tap.c', 'virtio_user/vhost_user.c', - 'virtio_user/vhost_vdpa.c', 'virtio_user/virtio_user_dev.c') deps += ['bus_vdev', 'common_virtio'] endif
drivers/net/virtio/virtio_ethdev.c +0 -2
@@ -2712,5 +2712,3 @@ __rte_unused uint8_t is_rx)return 0 ; } -RTE_LOG_REGISTER_SUFFIX (virtio_logtype_init, init,NOTICE ); -RTE_LOG_REGISTER_SUFFIX (virtio_logtype_driver, driver,NOTICE );
drivers/net/virtio/virtio_user/vhost_kernel.c +3 -1
@@ -11,9 +11,11 @@#include <rte_memory.h> -#include "vhost.h" +#include "virtio_user/vhost.h" +#include "virtio_user_dev.h" #include "vhost_kernel_tap.h" +#include "../virtqueue.h" struct vhost_kernel_data {int *vhostfds;
drivers/net/virtio/virtio_user/vhost_user.c +1 -1
@@ -16,7 +16,7 @@#include <rte_string_fns.h> #include <rte_fbarray.h> -#include "vhost.h" +#include "virtio_user/vhost.h" #include "virtio_user_dev.h" struct vhost_user_data {
drivers/net/virtio/virtio_user/virtio_user_dev.c +4 -2
@@ -20,10 +20,12 @@#include <rte_malloc.h> #include <rte_io.h> -#include "vhost.h" -#include "virtio.h" +#include "virtio_user/vhost.h" +#include "virtio_user_dev.h" +#include "../virtqueue.h" #include "../virtio_ethdev.h" +#include "../virtio_net_logs.h" #define VIRTIO_USER_MEM_EVENT_CLB_NAME "virtio_user_mem_event_clb"
drivers/net/virtio/virtio_user/virtio_user_dev.h +14 -10
@@ -25,26 +25,36 @@ struct virtio_user_queue { };struct virtio_user_dev { -struct virtio_hw hw; +union { +struct virtio_hw hw; +uint8_t dummy[256 ]; + }; + +void *backend_data; +uint16_t **notify_area; +char path[PATH_MAX ]; +bool hw_cvq; +uint16_t max_queue_pairs; +uint64_t device_features;/* supported features by device */ +bool *qp_enabled; +enum virtio_user_backend_type backend_type;bool is_server;/* server or client mode */ int *callfds;int *kickfds;int mac_specified; -uint16_t max_queue_pairs; +uint16_t queue_pairs;uint32_t queue_size;uint64_t features;/* the negotiated features with driver, * and will be sync with device */ -uint64_t device_features;/* supported features by device */ uint64_t frontend_features;/* enabled frontend features */ uint64_t unsupported_features;/* unsupported features mask */ uint8_t status;uint16_t net_status;uint8_t mac_addr[RTE_ETHER_ADDR_LEN ]; -char path[PATH_MAX ];char *ifname;union {
@@ -54,18 +64,12 @@ struct virtio_user_dev { } vrings;struct virtio_user_queue *packed_queues; -bool *qp_enabled;struct virtio_user_backend_ops *ops;pthread_mutex_t mutex;bool started; -bool hw_cvq;struct virtqueue *scvq; - -void *backend_data; - -uint16_t **notify_area; };int virtio_user_dev_set_features (struct virtio_user_dev *dev);
drivers/net/virtio/virtio_user_ethdev.c +1 -1
@@ -21,13 +21,13 @@#include <rte_io.h> #include "virtio_net_logs.h" +#include "virtio_user/vhost.h" #include "virtio_ethdev.h" #include "virtio.h" #include "virtqueue.h" #include "virtio_rxtx.h" #include "virtio_user/virtio_user_dev.h" -#include "virtio_user/vhost.h" #define virtio_user_get_dev (hwp) container_of(hwp, struct virtio_user_dev, hw)
Signature · 1 line
2.25.1
PATCH 14/16 common/virtio: support cryptodev in vdev setup
In reply to Gowrishankar MuthukrishnanSupport cryptodev in vdev setup.
--- drivers/common/virtio/virtio_user/vhost_vdpa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/common/virtio/virtio_user/vhost_vdpa.c +2 -1
@@ -122,6 +122,7 @@ struct virtio_user_dev {#define VIRTIO_NET_F_CTRL_VQ 17#define VIRTIO_F_IOMMU_PLATFORM 33#define VIRTIO_ID_NETWORK 0x01 +#define VIRTIO_ID_CRYPTO 0x20static int vhost_vdpa_set_owner (struct virtio_user_dev *dev)
@@ -560,7 +561,7 @@ vhost_vdpa_setup(struct virtio_user_dev *dev) }if (ioctl (data->vhostfd,VHOST_VDPA_GET_DEVICE_ID , &did) <0 || - did !=VIRTIO_ID_NETWORK ) { + (did !=VIRTIO_ID_NETWORK ) || (did !=VIRTIO_ID_CRYPTO )) {PMD_DRV_LOG (ERR ,"Invalid vdpa device ID: %u" , did);close (data->vhostfd);free (data);
Signature · 1 line
2.25.1
PATCH 15/16 crypto/virtio: add vhost backend to virtio_user
In reply to Gowrishankar MuthukrishnanAdd vhost backend to virtio_user crypto.
--- drivers/crypto/virtio/meson.build | 7 + drivers/crypto/virtio/virtio_cryptodev.c | 57 +- drivers/crypto/virtio/virtio_cryptodev.h | 3 + drivers/crypto/virtio/virtio_pci.h | 7 + drivers/crypto/virtio/virtio_ring.h | 6 - .../crypto/virtio/virtio_user/vhost_vdpa.c | 310 +++++++ .../virtio/virtio_user/virtio_user_dev.c | 774 ++++++++++++++++++ .../virtio/virtio_user/virtio_user_dev.h | 88 ++ drivers/crypto/virtio/virtio_user_cryptodev.c | 586 +++++++++++++ 9 files changed, 1810 insertions(+), 28 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_user/vhost_vdpa.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.h create mode 100644 drivers/crypto/virtio/virtio_user_cryptodev.c
drivers/crypto/virtio/meson.build +7 -0
@@ -17,3 +17,10 @@ sources = files( 'virtio_rxtx.c', 'virtqueue.c', ) + +if is_linux + sources += files('virtio_user_cryptodev.c', + 'virtio_user/vhost_vdpa.c', + 'virtio_user/virtio_user_dev.c') + deps += ['bus_vdev', 'common_virtio'] +endif
drivers/crypto/virtio/virtio_cryptodev.c +35 -22
75 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +3 -0
@@ -74,4 +74,7 @@ uint16_t virtio_crypto_pkt_rx_burst(void *tx_queue,struct rte_crypto_op **tx_pkts, uint16_t nb_pkts); +int crypto_virtio_dev_init (struct rte_cryptodev *cryptodev,uint64_t features, +struct rte_pci_device *pci_dev); +#endif /* _VIRTIO_CRYPTODEV_H_ */
drivers/crypto/virtio/virtio_pci.h +7 -0
@@ -20,6 +20,9 @@ struct virtqueue;#define VIRTIO_CRYPTO_PCI_VENDORID 0x1AF4#define VIRTIO_CRYPTO_PCI_DEVICEID 0x1054 +/* VirtIO device IDs. */ +#define VIRTIO_ID_CRYPTO 20 +/* VirtIO ABI version, this must match exactly. */ #define VIRTIO_PCI_ABI_VERSION 0
@@ -56,8 +59,12 @@ struct virtqueue;#define VIRTIO_CONFIG_STATUS_DRIVER 0x02#define VIRTIO_CONFIG_STATUS_DRIVER_OK 0x04#define VIRTIO_CONFIG_STATUS_FEATURES_OK 0x08 +#define VIRTIO_CONFIG_STATUS_DEV_NEED_RESET 0x40#define VIRTIO_CONFIG_STATUS_FAILED 0x80 +/* The alignment to use between consumer and producer parts of vring. */ +#define VIRTIO_VRING_ALIGN 4096 +/* * Each virtqueue indirect descriptor list must be physically contiguous. * To allow us to malloc(9) each list individually, limit the number
drivers/crypto/virtio/virtio_ring.h +0 -6
@@ -181,12 +181,6 @@ vring_init_packed(struct vring_packed *vr, uint8_t *p, rte_iova_t iova, sizeof(struct vring_packed_desc_event)), align); } -static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) -{ -vring_init_split (vr, p,0 , align, num); -} -/* * The following is used with VIRTIO_RING_F_EVENT_IDX. * Assuming a given event_idx value from the other size, if we have
drivers/crypto/virtio/virtio_user/vhost_vdpa.c new file +310 -0
310 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/virtio_user_dev.c new file +774 -0
774 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/virtio_user_dev.h new file +88 -0
88 lines not on this page · raw message
drivers/crypto/virtio/virtio_user_cryptodev.c new file +586 -0
586 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH 16/16 test/crypto: test virtio_crypto_user PMD
In reply to Gowrishankar MuthukrishnanReuse virtio_crypto tests for testing virtio_crypto_user PMD.
--- app/test/test_cryptodev.c | 7 +++++++ app/test/test_cryptodev.h | 1 + app/test/test_cryptodev_asym.c | 15 +++++++++++++++ 3 files changed, 23 insertions(+)
app/test/test_cryptodev.c +7 -0
@@ -19737,6 +19737,12 @@ test_cryptodev_virtio(void)return run_cryptodev_testsuite (RTE_STR (CRYPTODEV_NAME_VIRTIO_PMD )); } +static int +test_cryptodev_virtio_user (void ) +{ +return run_cryptodev_testsuite (RTE_STR (CRYPTODEV_NAME_VIRTIO_USER_PMD )); +} +static int test_cryptodev_aesni_mb (void ) {
@@ -20074,6 +20080,7 @@ REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);REGISTER_DRIVER_TEST (cryptodev_ccp_autotest, test_cryptodev_ccp);REGISTER_DRIVER_TEST (cryptodev_uadk_autotest, test_cryptodev_uadk);REGISTER_DRIVER_TEST (cryptodev_virtio_autotest, test_cryptodev_virtio); +REGISTER_DRIVER_TEST (cryptodev_virtio_user_autotest, test_cryptodev_virtio_user);REGISTER_DRIVER_TEST (cryptodev_octeontx_autotest, test_cryptodev_octeontx);REGISTER_DRIVER_TEST (cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);REGISTER_DRIVER_TEST (cryptodev_nitrox_autotest, test_cryptodev_nitrox);
app/test/test_cryptodev.h +1 -0
@@ -64,6 +64,7 @@#define CRYPTODEV_NAME_MVSAM_PMD crypto_mvsam#define CRYPTODEV_NAME_CCP_PMD crypto_ccp#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +#define CRYPTODEV_NAME_VIRTIO_USER_PMD crypto_virtio_user#define CRYPTODEV_NAME_OCTEONTX_SYM_PMD crypto_octeontx#define CRYPTODEV_NAME_CAAM_JR_PMD crypto_caam_jr#define CRYPTODEV_NAME_NITROX_PMD crypto_nitrox_sym
app/test/test_cryptodev_asym.c +15 -0
@@ -4092,7 +4092,22 @@ test_cryptodev_virtio_asym(void)return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); } +static int +test_cryptodev_virtio_user_asym (void ) +{ + gbl_driver_id =rte_cryptodev_driver_id_get ( +RTE_STR (CRYPTODEV_NAME_VIRTIO_USER_PMD )); +if (gbl_driver_id ==-1 ) { +RTE_LOG (ERR ,USER1 ,"virtio user PMD must be loaded.\n" ); +return TEST_FAILED ; + } + +/* Use test suite registered for crypto_virtio_user PMD */ +return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); +} +REGISTER_DRIVER_TEST (cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym); +REGISTER_DRIVER_TEST (cryptodev_virtio_user_asym_autotest, test_cryptodev_virtio_user_asym);REGISTER_DRIVER_TEST (cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);REGISTER_DRIVER_TEST (cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);
Signature · 1 line
2.25.1
v2 cover crypto/virtio: add RSA support
In reply to Gowrishankar MuthukrishnanThis series adds RSA support in virtio crypto PMD.
v2:
- split from v1 series.
Gowrishankar Muthukrishnan (2):
crypto/virtio: add asymmetric RSA support test/crypto: add asymmetric tests for virtio PMD
app/test/test_cryptodev_asym.c | 29 ++ app/test/test_cryptodev_rsa_test_vectors.h | 4 + .../virtio/virtio_crypto_capabilities.h | 19 + drivers/crypto/virtio/virtio_cryptodev.c | 384 +++++++++++++++--- drivers/crypto/virtio/virtio_rxtx.c | 226 ++++++++++- lib/cryptodev/cryptodev_pmd.h | 6 + lib/vhost/virtio_crypto.h | 80 ++++ 7 files changed, 680 insertions(+), 68 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 crypto/virtio: add asymmetric RSA support
Asymmetric RSA operations (SIGN, VERIFY, ENCRYPT and DECRYPT) are supported in virtio PMD.
--- .../virtio/virtio_crypto_capabilities.h | 19 + drivers/crypto/virtio/virtio_cryptodev.c | 384 +++++++++++++++--- drivers/crypto/virtio/virtio_rxtx.c | 226 ++++++++++- lib/cryptodev/cryptodev_pmd.h | 6 + lib/vhost/virtio_crypto.h | 80 ++++ 5 files changed, 647 insertions(+), 68 deletions(-)
drivers/crypto/virtio/virtio_crypto_capabilities.h +19 -0
@@ -48,4 +48,23 @@ }, } \ } +#define VIRTIO_ASYM_CAPABILITIES \ + { /* RSA */ \ + .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC, \ + {.asym = { \ + .xform_capa = { \ + .xform_type = RTE_CRYPTO_ASYM_XFORM_RSA, \ + .op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) | \ + (1 << RTE_CRYPTO_ASYM_OP_VERIFY) | \ + (1 << RTE_CRYPTO_ASYM_OP_ENCRYPT) | \ + (1 << RTE_CRYPTO_ASYM_OP_DECRYPT)), \ + {.modlen = { \ + .min = 1, \ + .max = 1024, \ + .increment = 1 \ + }, } \ + } \ + }, } \ + } +#endif /* _VIRTIO_CRYPTO_CAPABILITIES_H_ */
drivers/crypto/virtio/virtio_cryptodev.c +332 -52
478 lines not on this page · raw message
drivers/crypto/virtio/virtio_rxtx.c +210 -16
249 lines not on this page · raw message
lib/cryptodev/cryptodev_pmd.h +6 -0
@@ -715,6 +715,12 @@ struct rte_cryptodev_asym_session {uint8_t sess_private_data[]; }; +/** +* Helper macro to get session private data +*/ +#define CRYPTODEV_GET_ASYM_SESS_PRIV (s) \ + ((void *)(((struct rte_cryptodev_asym_session *)s)->sess_private_data)) + #ifdef __cplusplus }#endif
lib/vhost/virtio_crypto.h +80 -0
128 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 2/2 test/crypto: add asymmetric tests for virtio PMD
In reply to Gowrishankar MuthukrishnanAdd asymmetric tests for Virtio PMD.
--- app/test/test_cryptodev_asym.c | 29 ++++++++++++++++++++++ app/test/test_cryptodev_rsa_test_vectors.h | 4 +++ 2 files changed, 33 insertions(+)
app/test/test_cryptodev_asym.c +29 -0
@@ -3997,6 +3997,19 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite = { } }; +static struct unit_test_suite cryptodev_virtio_asym_testsuite = { + .suite_name ="Crypto Device VIRTIO ASYM Unit Test Suite" , + .setup = testsuite_setup, + .teardown = testsuite_teardown, + .unit_test_cases = { +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, test_capability), +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, + test_rsa_sign_verify_crt), +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec_crt), +TEST_CASES_END ()/**< NULL terminate unit test array */ + } +}; +static int test_cryptodev_openssl_asym (void ) {
@@ -4065,6 +4078,22 @@ test_cryptodev_cn10k_asym(void)return unit_test_suite_runner (&cryptodev_octeontx_asym_testsuite); } +static int +test_cryptodev_virtio_asym (void ) +{ + gbl_driver_id =rte_cryptodev_driver_id_get ( +RTE_STR (CRYPTODEV_NAME_VIRTIO_PMD )); +if (gbl_driver_id ==-1 ) { +RTE_LOG (ERR ,USER1 ,"virtio PMD must be loaded.\n" ); +return TEST_FAILED ; + } + +/* Use test suite registered for crypto_virtio PMD */ +return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); +} + +REGISTER_DRIVER_TEST (cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym); +REGISTER_DRIVER_TEST (cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);REGISTER_DRIVER_TEST (cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);REGISTER_DRIVER_TEST (cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);
app/test/test_cryptodev_rsa_test_vectors.h +4 -0
@@ -377,6 +377,10 @@ struct rte_crypto_asym_xform rsa_xform_crt = { .length = sizeof(rsa_e) }, .key_type = RTE_RSA_KEY_TYPE_QT, + .d = { + .data = rsa_d, + .length =sizeof (rsa_d) + }, .qt = { .p = { .data = rsa_p,
Signature · 1 line
2.25.1
v3 cover crypto/virtio: enhancements for RSA and vDPA
In reply to Gowrishankar MuthukrishnanThis patch series enhances virtio crypto PMD to:
* support RSA
* support packed virtio ring
* support vDPA backend
v3:
- vDPA backend code majorly sourced from virtio net.
Gowrishankar Muthukrishnan (6):
crypto/virtio: add asymmetric RSA support crypto/virtio: refactor queue operations crypto/virtio: add packed ring support crypto/virtio: add vDPA backend test/crypto: add asymmetric tests for virtio PMD test/crypto: add tests for virtio user PMD
app/test/test_cryptodev.c | 7 + app/test/test_cryptodev.h | 1 + app/test/test_cryptodev_asym.c | 43 + drivers/crypto/virtio/meson.build | 8 + drivers/crypto/virtio/virtio_crypto_algs.h | 2 +- .../virtio/virtio_crypto_capabilities.h | 19 + drivers/crypto/virtio/virtio_cryptodev.c | 1060 +++++++++++------ drivers/crypto/virtio/virtio_cryptodev.h | 18 +- drivers/crypto/virtio/virtio_cvq.c | 228 ++++ drivers/crypto/virtio/virtio_cvq.h | 33 + drivers/crypto/virtio/virtio_logs.h | 6 +- drivers/crypto/virtio/virtio_pci.h | 38 +- drivers/crypto/virtio/virtio_ring.h | 65 +- drivers/crypto/virtio/virtio_rxtx.c | 721 ++++++++++- drivers/crypto/virtio/virtio_rxtx.h | 13 + drivers/crypto/virtio/virtio_user/vhost.h | 90 ++ .../crypto/virtio/virtio_user/vhost_vdpa.c | 710 +++++++++++ .../virtio/virtio_user/virtio_user_dev.c | 767 ++++++++++++ .../virtio/virtio_user/virtio_user_dev.h | 85 ++ drivers/crypto/virtio/virtio_user_cryptodev.c | 575 +++++++++ drivers/crypto/virtio/virtqueue.c | 229 +++- drivers/crypto/virtio/virtqueue.h | 221 +++- lib/cryptodev/cryptodev_pmd.h | 6 + 23 files changed, 4453 insertions(+), 492 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_cvq.c create mode 100644 drivers/crypto/virtio/virtio_cvq.h create mode 100644 drivers/crypto/virtio/virtio_rxtx.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost_vdpa.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.h create mode 100644 drivers/crypto/virtio/virtio_user_cryptodev.c
Signature · 1 line
2.25.1
PATCH v3 1/6 crypto/virtio: add asymmetric RSA support
Asymmetric RSA operations (SIGN, VERIFY, ENCRYPT and DECRYPT) are supported in virtio PMD.
---
Depends-on: series-34674 ("vhost: add RSA support")
v3:
- fast path optimizations.
--- .../virtio/virtio_crypto_capabilities.h | 19 + drivers/crypto/virtio/virtio_cryptodev.c | 347 +++++++++++++++--- drivers/crypto/virtio/virtio_cryptodev.h | 2 + drivers/crypto/virtio/virtio_rxtx.c | 243 ++++++++++-- lib/cryptodev/cryptodev_pmd.h | 6 + 5 files changed, 539 insertions(+), 78 deletions(-)
drivers/crypto/virtio/virtio_crypto_capabilities.h +19 -0
@@ -48,4 +48,23 @@ }, } \ } +#define VIRTIO_ASYM_CAPABILITIES \ + { /* RSA */ \ + .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC, \ + {.asym = { \ + .xform_capa = { \ + .xform_type = RTE_CRYPTO_ASYM_XFORM_RSA, \ + .op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) | \ + (1 << RTE_CRYPTO_ASYM_OP_VERIFY) | \ + (1 << RTE_CRYPTO_ASYM_OP_ENCRYPT) | \ + (1 << RTE_CRYPTO_ASYM_OP_DECRYPT)), \ + {.modlen = { \ + .min = 1, \ + .max = 1024, \ + .increment = 1 \ + }, } \ + } \ + }, } \ + } +#endif /* _VIRTIO_CRYPTO_CAPABILITIES_H_ */
drivers/crypto/virtio/virtio_cryptodev.c +302 -45
444 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +2 -0
@@ -20,6 +20,8 @@#define VIRTIO_CRYPTO_MAX_KEY_SIZE 256 +#define VIRTIO_CRYPTO_MAX_CTRL_DATA 2048 +extern uint8_t cryptodev_virtio_driver_id;enum virtio_crypto_cmd_id {
drivers/crypto/virtio/virtio_rxtx.c +210 -33
285 lines not on this page · raw message
lib/cryptodev/cryptodev_pmd.h +6 -0
@@ -715,6 +715,12 @@ struct rte_cryptodev_asym_session {uint8_t sess_private_data[]; }; +/** +* Helper macro to get session private data +*/ +#define CRYPTODEV_GET_ASYM_SESS_PRIV (s) \ + ((void *)(((struct rte_cryptodev_asym_session *)s)->sess_private_data)) + #ifdef __cplusplus }#endif
Signature · 1 line
2.25.1
PATCH v3 2/6 crypto/virtio: refactor queue operations
In reply to Gowrishankar MuthukrishnanMove existing control queue operations into a common place that would be shared with other virtio type of devices.
--- drivers/crypto/virtio/meson.build | 1 + drivers/crypto/virtio/virtio_crypto_algs.h | 2 +- drivers/crypto/virtio/virtio_cryptodev.c | 563 ++++++++------------- drivers/crypto/virtio/virtio_cvq.c | 129 +++++ drivers/crypto/virtio/virtio_cvq.h | 33 ++ drivers/crypto/virtio/virtio_pci.h | 6 +- drivers/crypto/virtio/virtio_ring.h | 12 +- drivers/crypto/virtio/virtio_rxtx.c | 42 +- drivers/crypto/virtio/virtio_rxtx.h | 13 + drivers/crypto/virtio/virtqueue.c | 191 ++++++- drivers/crypto/virtio/virtqueue.h | 89 +++- 11 files changed, 691 insertions(+), 390 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_cvq.c create mode 100644 drivers/crypto/virtio/virtio_cvq.h create mode 100644 drivers/crypto/virtio/virtio_rxtx.h
drivers/crypto/virtio/meson.build +1 -0
@@ -11,6 +11,7 @@ includes += include_directories('../../../lib/vhost') deps += 'bus_pci' sources = files( 'virtio_cryptodev.c', + 'virtio_cvq.c', 'virtio_pci.c', 'virtio_rxtx.c', 'virtqueue.c',
drivers/crypto/virtio/virtio_crypto_algs.h +1 -1
@@ -22,7 +22,7 @@ struct virtio_crypto_session { phys_addr_t phys_addr; } aad; -struct virtio_crypto_op_ctrl_req ctrl; +struct virtio_pmd_ctrl ctrl; };#endif /* _VIRTIO_CRYPTO_ALGS_H_ */
drivers/crypto/virtio/virtio_cryptodev.c +217 -346
768 lines not on this page · raw message
drivers/crypto/virtio/virtio_cvq.c new file +129 -0
129 lines not on this page · raw message
drivers/crypto/virtio/virtio_cvq.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Marvell +*/ + +#ifndef _VIRTIO_CVQ_H_ +#define _VIRTIO_CVQ_H_ + +#include <rte_spinlock.h> +#include <virtio_crypto.h> + +#include "virtio_cryptodev.h" + +struct virtqueue ; + +struct virtcrypto_ctl { +const struct rte_memzone *hdr_mz;/**< memzone to populate hdr. */ +rte_iova_t hdr_mem;/**< hdr for each xmit packet */ +rte_spinlock_t lock;/**< spinlock for control queue. */ +void (*notify_queue)(struct virtqueue *vq,void *cookie);/**< notify ops. */ +void *notify_cookie;/**< cookie for notify ops */ +}; + +struct virtio_pmd_ctrl { +struct virtio_crypto_op_ctrl_req hdr; +struct virtio_crypto_session_input input; +uint8_t data[VIRTIO_CRYPTO_MAX_CTRL_DATA ]; +}; + +int +virtio_crypto_send_command (struct virtcrypto_ctl *cvq,struct virtio_pmd_ctrl *ctrl, +int *dlen,int pkt_num); + +#endif /* _VIRTIO_CVQ_H_ */
drivers/crypto/virtio/virtio_pci.h +4 -2
@@ -176,8 +176,7 @@ struct virtio_pci_ops { };struct virtio_crypto_hw { -/* control queue */ -struct virtqueue *cvq; +struct virtqueue **vqs;uint16_t dev_id;uint16_t max_dataqueues;uint64_t req_guest_features;
@@ -190,6 +189,9 @@ struct virtio_crypto_hw {struct virtio_pci_common_cfg *common_cfg;struct virtio_crypto_config *dev_cfg;const struct rte_cryptodev_capabilities *virtio_dev_capabilities; +uint8_t weak_barriers; +struct virtcrypto_ctl *cvq; +bool use_va; };/*
drivers/crypto/virtio/virtio_ring.h +10 -2
@@ -59,6 +59,7 @@ struct vring_used {struct vring {unsigned int num; +rte_iova_t desc_iova;struct vring_desc *desc;struct vring_avail *avail;struct vring_used *used;
@@ -111,17 +112,24 @@ vring_size(unsigned int num, unsigned long align) }static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p, -unsigned long align) +vring_init_split (struct vring *vr,uint8_t *p,rte_iova_t iova, +unsigned long align,unsigned int num) { vr->num = num; vr->desc = (struct vring_desc *) p; + vr->desc_iova = iova; vr->avail = (struct vring_avail *) (p + num *sizeof (struct vring_desc )); vr->used = (void *)RTE_ALIGN_CEIL ((uintptr_t )(&vr->avail->ring[num]), align); } +static inline void +vring_init (struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) +{ +vring_init_split (vr, p,0 , align, num); +} +/* * The following is used with VIRTIO_RING_F_EVENT_IDX. * Assuming a given event_idx value from the other size, if we have
drivers/crypto/virtio/virtio_rxtx.c +16 -26
111 lines not on this page · raw message
drivers/crypto/virtio/virtio_rxtx.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Marvell. +*/ + +#ifndef _VIRTIO_RXTX_H_ +#define _VIRTIO_RXTX_H_ + +struct virtcrypto_data { +const struct rte_memzone *hdr_mz;/**< memzone to populate hdr. */ +rte_iova_t hdr_mem;/**< hdr for each xmit packet */ +}; + +#endif /* _VIRTIO_RXTX_H_ */
drivers/crypto/virtio/virtqueue.c +188 -3
212 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h +79 -10
162 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 3/6 crypto/virtio: add packed ring support
In reply to Gowrishankar MuthukrishnanAdd packed ring support.
--- drivers/crypto/virtio/virtio_cryptodev.c | 125 +++++++ drivers/crypto/virtio/virtio_cryptodev.h | 13 +- drivers/crypto/virtio/virtio_cvq.c | 103 +++++- drivers/crypto/virtio/virtio_pci.h | 25 ++ drivers/crypto/virtio/virtio_ring.h | 59 ++- drivers/crypto/virtio/virtio_rxtx.c | 444 ++++++++++++++++++++++- drivers/crypto/virtio/virtqueue.c | 50 ++- drivers/crypto/virtio/virtqueue.h | 134 ++++++- 8 files changed, 924 insertions(+), 29 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +125 -0
@@ -869,6 +869,125 @@ virtio_crypto_clear_session(rte_free (ctrl); } +static void +virtio_crypto_clear_session_packed ( +struct rte_cryptodev *dev, +struct virtio_crypto_op_ctrl_req *ctrl) +{ +struct virtio_crypto_hw *hw; +struct virtqueue *vq; +struct vring_packed_desc *desc; +uint8_t *status; +uint8_t needed =1 ; +uint32_t head; +uint64_t malloc_phys_addr; +uint8_t len_inhdr =sizeof (struct virtio_crypto_inhdr ); +uint32_t len_op_ctrl_req =sizeof (struct virtio_crypto_op_ctrl_req ); +uint64_t session_id = ctrl->u.destroy_session.session_id; +uint16_t flags; +uint8_t nb_descs =0 ; + + hw = dev->data->dev_private; + vq =virtcrypto_cq_to_vq (hw->cvq); + head = vq->vq_avail_idx; + flags = vq->vq_packed.cached_flags; + +VIRTIO_CRYPTO_SESSION_LOG_INFO ("vq->vq_desc_head_idx = %d, " +"vq = %p" , vq->vq_desc_head_idx, vq); + +if (vq->vq_free_cnt < needed) { +VIRTIO_CRYPTO_SESSION_LOG_ERR ( +"vq->vq_free_cnt = %d is less than %d, " +"not enough" , vq->vq_free_cnt, needed); +return ; + } + + malloc_phys_addr =rte_malloc_virt2iova (ctrl); + +/* status part */ + status = &(((struct virtio_crypto_inhdr *) + ((uint8_t *)ctrl + len_op_ctrl_req))->status); + *status =VIRTIO_CRYPTO_ERR ; + +/* indirect desc vring part */ + desc = vq->vq_packed.ring.desc; + +/* ctrl request part */ + desc[head].addr = malloc_phys_addr; + desc[head].len = len_op_ctrl_req; + desc[head].flags =VRING_DESC_F_NEXT | vq->vq_packed.cached_flags; + vq->vq_free_cnt--; + nb_descs++; +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^=VRING_PACKED_DESC_F_AVAIL_USED ; + } + +/* status part */ + desc[vq->vq_avail_idx].addr = malloc_phys_addr + len_op_ctrl_req; + desc[vq->vq_avail_idx].len = len_inhdr; + desc[vq->vq_avail_idx].flags =VRING_DESC_F_WRITE ; + vq->vq_free_cnt--; + nb_descs++; +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^=VRING_PACKED_DESC_F_AVAIL_USED ; + } + +virtqueue_store_flags_packed (&desc[head],VRING_DESC_F_NEXT | flags, + vq->hw->weak_barriers); + +virtio_wmb (vq->hw->weak_barriers); +virtqueue_notify (vq); + +/* wait for used desc in virtqueue +* desc_is_used has a load-acquire or rte_io_rmb inside +*/ +rte_rmb (); +while (!desc_is_used (&desc[head], vq)) { +rte_rmb (); +usleep (100 ); + } + +/* now get used descriptors */ + vq->vq_free_cnt += nb_descs; + vq->vq_used_cons_idx += nb_descs; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +PMD_INIT_LOG (DEBUG ,"vq->vq_free_cnt=%d " +"vq->vq_queue_idx=%d " +"vq->vq_avail_idx=%d " +"vq->vq_used_cons_idx=%d " +"vq->vq_packed.cached_flags=0x%x " +"vq->vq_packed.used_wrap_counter=%d" , + vq->vq_free_cnt, + vq->vq_queue_index, + vq->vq_avail_idx, + vq->vq_used_cons_idx, + vq->vq_packed.cached_flags, + vq->vq_packed.used_wrap_counter); + +if (*status !=VIRTIO_CRYPTO_OK ) { +VIRTIO_CRYPTO_SESSION_LOG_ERR ("Close session failed " +"status=%" PRIu32", session_id=%" PRIu64"" , + *status, session_id); +rte_free (ctrl); +return ; + } + +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_free_cnt=%d " +"vq->vq_desc_head_idx=%d" , + vq->vq_free_cnt, vq->vq_desc_head_idx); + +VIRTIO_CRYPTO_SESSION_LOG_INFO ("Close session %" PRIu64" successfully " , + session_id); + +rte_free (ctrl); +} + static void virtio_crypto_sym_clear_session( struct rte_cryptodev *dev,
@@ -906,6 +1025,9 @@ virtio_crypto_sym_clear_session( ctrl->header.queue_id =0 ; ctrl->u.destroy_session.session_id = session->session_id; +if (vtpci_with_packed_queue (dev->data->dev_private)) +return virtio_crypto_clear_session_packed (dev, ctrl); +return virtio_crypto_clear_session (dev, ctrl); }
@@ -943,6 +1065,9 @@ virtio_crypto_asym_clear_session( ctrl->header.queue_id =0 ; ctrl->u.destroy_session.session_id = session->session_id; +if (vtpci_with_packed_queue (dev->data->dev_private)) +return virtio_crypto_clear_session_packed (dev, ctrl); +return virtio_crypto_clear_session (dev, ctrl); }
drivers/crypto/virtio/virtio_cryptodev.h +12 -1
@@ -10,13 +10,21 @@#include "virtio_ring.h" /* Features desired/implemented by this driver. */ -#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1) +#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1 | \ + 1ULL << VIRTIO_F_IN_ORDER | \ + 1ULL << VIRTIO_F_RING_PACKED | \ + 1ULL << VIRTIO_F_NOTIFICATION_DATA | \ + 1ULL << VIRTIO_RING_F_INDIRECT_DESC | \ + 1ULL << VIRTIO_F_ORDER_PLATFORM)#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7#define VIRTIO_CRYPTO_MAX_IV_SIZE 16 +#define VIRTIO_CRYPTO_MAX_MSG_SIZE 512 +#define VIRTIO_CRYPTO_MAX_SIGN_SIZE 512 +#define VIRTIO_CRYPTO_MAX_CIPHER_SIZE 1024#define VIRTIO_CRYPTO_MAX_KEY_SIZE 256
@@ -36,6 +44,9 @@ struct virtio_crypto_op_cookie {struct virtio_crypto_inhdr inhdr;struct vring_desc desc[NUM_ENTRY_VIRTIO_CRYPTO_OP ];uint8_t iv[VIRTIO_CRYPTO_MAX_IV_SIZE ]; +uint8_t message[VIRTIO_CRYPTO_MAX_MSG_SIZE ]; +uint8_t sign[VIRTIO_CRYPTO_MAX_SIGN_SIZE ]; +uint8_t cipher[VIRTIO_CRYPTO_MAX_CIPHER_SIZE ]; };/*
drivers/crypto/virtio/virtio_cvq.c +101 -2
115 lines not on this page · raw message
drivers/crypto/virtio/virtio_pci.h +25 -0
@@ -83,6 +83,25 @@ struct virtqueue;#define VIRTIO_F_VERSION_1 32#define VIRTIO_F_IOMMU_PLATFORM 33 +#define VIRTIO_F_RING_PACKED 34 + +/* +* Inorder feature indicates that all buffers are used by the device +* in the same order in which they have been made available. +*/ +#define VIRTIO_F_IN_ORDER 35 + +/* +* This feature indicates that memory accesses by the driver and the device +* are ordered in a way described by the platform. +*/ +#define VIRTIO_F_ORDER_PLATFORM 36 + +/* +* This feature indicates that the driver passes extra data (besides +* identifying the virtqueue) in its device notifications. +*/ +#define VIRTIO_F_NOTIFICATION_DATA 38/* The Guest publishes the used index for which it expects an interrupt * at the end of the avail ring. Host should ignore the avail->flags field.
@@ -230,6 +249,12 @@ vtpci_with_feature(struct virtio_crypto_hw *hw, uint64_t bit)return (hw->guest_features & (1ULL << bit)) !=0 ; } +static inline int +vtpci_with_packed_queue (struct virtio_crypto_hw *hw) +{ +return vtpci_with_feature (hw,VIRTIO_F_RING_PACKED ); +} +/* * Function declaration from virtio_pci.c */
drivers/crypto/virtio/virtio_ring.h +58 -1
86 lines not on this page · raw message
drivers/crypto/virtio/virtio_rxtx.c +433 -11
496 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.c +42 -8
84 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h +128 -6
175 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 4/6 crypto/virtio: add vDPA backend
In reply to Gowrishankar MuthukrishnanAdd vDPA backend to virtio_user crypto.
--- drivers/crypto/virtio/meson.build | 7 + drivers/crypto/virtio/virtio_cryptodev.c | 57 +- drivers/crypto/virtio/virtio_cryptodev.h | 3 + drivers/crypto/virtio/virtio_logs.h | 6 +- drivers/crypto/virtio/virtio_pci.h | 7 + drivers/crypto/virtio/virtio_ring.h | 6 - drivers/crypto/virtio/virtio_user/vhost.h | 90 ++ .../crypto/virtio/virtio_user/vhost_vdpa.c | 710 ++++++++++++++++ .../virtio/virtio_user/virtio_user_dev.c | 767 ++++++++++++++++++ .../virtio/virtio_user/virtio_user_dev.h | 85 ++ drivers/crypto/virtio/virtio_user_cryptodev.c | 575 +++++++++++++ 11 files changed, 2283 insertions(+), 30 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_user/vhost.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost_vdpa.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.h create mode 100644 drivers/crypto/virtio/virtio_user_cryptodev.c
drivers/crypto/virtio/meson.build +7 -0
@@ -16,3 +16,10 @@ sources = files( 'virtio_rxtx.c', 'virtqueue.c', ) + +if is_linux + sources += files('virtio_user_cryptodev.c', + 'virtio_user/vhost_vdpa.c', + 'virtio_user/virtio_user_dev.c') + deps += ['bus_vdev'] +endif
drivers/crypto/virtio/virtio_cryptodev.c +35 -22
75 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +3 -0
@@ -76,4 +76,7 @@ uint16_t virtio_crypto_pkt_rx_burst(void *tx_queue,struct rte_crypto_op **tx_pkts, uint16_t nb_pkts); +int crypto_virtio_dev_init (struct rte_cryptodev *cryptodev,uint64_t features, +struct rte_pci_device *pci_dev); +#endif /* _VIRTIO_CRYPTODEV_H_ */
drivers/crypto/virtio/virtio_logs.h +4 -2
@@ -15,8 +15,10 @@ extern int virtio_crypto_logtype_init;#define PMD_INIT_FUNC_TRACE () PMD_INIT_LOG(DEBUG, " >>") -extern int virtio_crypto_logtype_init; -#define RTE_LOGTYPE_VIRTIO_CRYPTO_INIT virtio_crypto_logtype_init +extern int virtio_crypto_logtype_driver; +#define RTE_LOGTYPE_VIRTIO_CRYPTO_DRIVER virtio_crypto_logtype_driver +#define PMD_DRV_LOG (level, ...) \ + RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_DRIVER, "%s(): ", __func__, __VA_ARGS__)#define VIRTIO_CRYPTO_INIT_LOG_IMPL (level, ...) \ RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_INIT, "%s(): ", __func__, __VA_ARGS__)
drivers/crypto/virtio/virtio_pci.h +7 -0
@@ -20,6 +20,9 @@ struct virtqueue;#define VIRTIO_CRYPTO_PCI_VENDORID 0x1AF4#define VIRTIO_CRYPTO_PCI_DEVICEID 0x1054 +/* VirtIO device IDs. */ +#define VIRTIO_ID_CRYPTO 20 +/* VirtIO ABI version, this must match exactly. */ #define VIRTIO_PCI_ABI_VERSION 0
@@ -56,8 +59,12 @@ struct virtqueue;#define VIRTIO_CONFIG_STATUS_DRIVER 0x02#define VIRTIO_CONFIG_STATUS_DRIVER_OK 0x04#define VIRTIO_CONFIG_STATUS_FEATURES_OK 0x08 +#define VIRTIO_CONFIG_STATUS_DEV_NEED_RESET 0x40#define VIRTIO_CONFIG_STATUS_FAILED 0x80 +/* The alignment to use between consumer and producer parts of vring. */ +#define VIRTIO_VRING_ALIGN 4096 +/* * Each virtqueue indirect descriptor list must be physically contiguous. * To allow us to malloc(9) each list individually, limit the number
drivers/crypto/virtio/virtio_ring.h +0 -6
@@ -181,12 +181,6 @@ vring_init_packed(struct vring_packed *vr, uint8_t *p, rte_iova_t iova, sizeof(struct vring_packed_desc_event)), align); } -static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) -{ -vring_init_split (vr, p,0 , align, num); -} -/* * The following is used with VIRTIO_RING_F_EVENT_IDX. * Assuming a given event_idx value from the other size, if we have
drivers/crypto/virtio/virtio_user/vhost.h new file +90 -0
90 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/vhost_vdpa.c new file +710 -0
710 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/virtio_user_dev.c new file +767 -0
767 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/virtio_user_dev.h new file +85 -0
85 lines not on this page · raw message
drivers/crypto/virtio/virtio_user_cryptodev.c new file +575 -0
575 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 5/6 test/crypto: add asymmetric tests for virtio PMD
In reply to Gowrishankar MuthukrishnanAdd asymmetric tests for Virtio PMD.
--- app/test/test_cryptodev_asym.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
app/test/test_cryptodev_asym.c +28 -0
@@ -4023,6 +4023,19 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite = { } }; +static struct unit_test_suite cryptodev_virtio_asym_testsuite = { + .suite_name ="Crypto Device VIRTIO ASYM Unit Test Suite" , + .setup = testsuite_setup, + .teardown = testsuite_teardown, + .unit_test_cases = { +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, test_capability), +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, + test_rsa_sign_verify_crt), +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec_crt), +TEST_CASES_END ()/**< NULL terminate unit test array */ + } +}; +static int test_cryptodev_openssl_asym (void ) {
@@ -4091,8 +4104,23 @@ test_cryptodev_cn10k_asym(void)return unit_test_suite_runner (&cryptodev_octeontx_asym_testsuite); } +static int +test_cryptodev_virtio_asym (void ) +{ + gbl_driver_id =rte_cryptodev_driver_id_get ( +RTE_STR (CRYPTODEV_NAME_VIRTIO_PMD )); +if (gbl_driver_id ==-1 ) { +RTE_LOG (ERR ,USER1 ,"virtio PMD must be loaded.\n" ); +return TEST_FAILED ; + } + +/* Use test suite registered for crypto_virtio PMD */ +return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); +} +REGISTER_DRIVER_TEST (cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);REGISTER_DRIVER_TEST (cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);REGISTER_DRIVER_TEST (cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);REGISTER_DRIVER_TEST (cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);REGISTER_DRIVER_TEST (cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym); +REGISTER_DRIVER_TEST (cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym);
Signature · 1 line
2.25.1
PATCH v3 6/6 test/crypto: add tests for virtio user PMD
In reply to Gowrishankar MuthukrishnanReuse virtio_crypto tests for testing virtio_crypto_user PMD.
--- app/test/test_cryptodev.c | 7 +++++++ app/test/test_cryptodev.h | 1 + app/test/test_cryptodev_asym.c | 15 +++++++++++++++ 3 files changed, 23 insertions(+)
app/test/test_cryptodev.c +7 -0
@@ -19737,6 +19737,12 @@ test_cryptodev_virtio(void)return run_cryptodev_testsuite (RTE_STR (CRYPTODEV_NAME_VIRTIO_PMD )); } +static int +test_cryptodev_virtio_user (void ) +{ +return run_cryptodev_testsuite (RTE_STR (CRYPTODEV_NAME_VIRTIO_USER_PMD )); +} +static int test_cryptodev_aesni_mb (void ) {
@@ -20074,6 +20080,7 @@ REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);REGISTER_DRIVER_TEST (cryptodev_ccp_autotest, test_cryptodev_ccp);REGISTER_DRIVER_TEST (cryptodev_uadk_autotest, test_cryptodev_uadk);REGISTER_DRIVER_TEST (cryptodev_virtio_autotest, test_cryptodev_virtio); +REGISTER_DRIVER_TEST (cryptodev_virtio_user_autotest, test_cryptodev_virtio_user);REGISTER_DRIVER_TEST (cryptodev_octeontx_autotest, test_cryptodev_octeontx);REGISTER_DRIVER_TEST (cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);REGISTER_DRIVER_TEST (cryptodev_nitrox_autotest, test_cryptodev_nitrox);
app/test/test_cryptodev.h +1 -0
@@ -64,6 +64,7 @@#define CRYPTODEV_NAME_MVSAM_PMD crypto_mvsam#define CRYPTODEV_NAME_CCP_PMD crypto_ccp#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +#define CRYPTODEV_NAME_VIRTIO_USER_PMD crypto_virtio_user#define CRYPTODEV_NAME_OCTEONTX_SYM_PMD crypto_octeontx#define CRYPTODEV_NAME_CAAM_JR_PMD crypto_caam_jr#define CRYPTODEV_NAME_NITROX_PMD crypto_nitrox_sym
app/test/test_cryptodev_asym.c +15 -0
@@ -4118,9 +4118,24 @@ test_cryptodev_virtio_asym(void)return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); } +static int +test_cryptodev_virtio_user_asym (void ) +{ + gbl_driver_id =rte_cryptodev_driver_id_get ( +RTE_STR (CRYPTODEV_NAME_VIRTIO_USER_PMD )); +if (gbl_driver_id ==-1 ) { +RTE_LOG (ERR ,USER1 ,"virtio user PMD must be loaded.\n" ); +return TEST_FAILED ; + } + +/* Use test suite registered for crypto_virtio_user PMD */ +return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); +} +REGISTER_DRIVER_TEST (cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);REGISTER_DRIVER_TEST (cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);REGISTER_DRIVER_TEST (cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);REGISTER_DRIVER_TEST (cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);REGISTER_DRIVER_TEST (cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym);REGISTER_DRIVER_TEST (cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym); +REGISTER_DRIVER_TEST (cryptodev_virtio_user_asym_autotest, test_cryptodev_virtio_user_asym);
Signature · 1 line
2.25.1
v4 cover crypto/virtio: enhancements for RSA and vDPA
In reply to Gowrishankar MuthukrishnanThis patch series enhances virtio crypto PMD to:
* support RSA
* support packed virtio ring
* support vDPA backend
v4:
- CI issue fixed.
Depends-on: series-34682 ("vhost: add RSA support")
Gowrishankar Muthukrishnan (6):
crypto/virtio: add asymmetric RSA support crypto/virtio: refactor queue operations crypto/virtio: add packed ring support crypto/virtio: add vDPA backend test/crypto: add asymmetric tests for virtio PMD test/crypto: add tests for virtio user PMD
app/test/test_cryptodev.c | 7 + app/test/test_cryptodev.h | 1 + app/test/test_cryptodev_asym.c | 43 + drivers/crypto/virtio/meson.build | 8 + drivers/crypto/virtio/virtio_crypto_algs.h | 2 +- .../virtio/virtio_crypto_capabilities.h | 19 + drivers/crypto/virtio/virtio_cryptodev.c | 1060 +++++++++++------ drivers/crypto/virtio/virtio_cryptodev.h | 18 +- drivers/crypto/virtio/virtio_cvq.c | 228 ++++ drivers/crypto/virtio/virtio_cvq.h | 33 + drivers/crypto/virtio/virtio_logs.h | 6 +- drivers/crypto/virtio/virtio_pci.h | 38 +- drivers/crypto/virtio/virtio_ring.h | 65 +- drivers/crypto/virtio/virtio_rxtx.c | 721 ++++++++++- drivers/crypto/virtio/virtio_rxtx.h | 13 + drivers/crypto/virtio/virtio_user/vhost.h | 90 ++ .../crypto/virtio/virtio_user/vhost_vdpa.c | 710 +++++++++++ .../virtio/virtio_user/virtio_user_dev.c | 749 ++++++++++++ .../virtio/virtio_user/virtio_user_dev.h | 85 ++ drivers/crypto/virtio/virtio_user_cryptodev.c | 575 +++++++++ drivers/crypto/virtio/virtqueue.c | 229 +++- drivers/crypto/virtio/virtqueue.h | 221 +++- lib/cryptodev/cryptodev_pmd.h | 6 + 23 files changed, 4435 insertions(+), 492 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_cvq.c create mode 100644 drivers/crypto/virtio/virtio_cvq.h create mode 100644 drivers/crypto/virtio/virtio_rxtx.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost_vdpa.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.h create mode 100644 drivers/crypto/virtio/virtio_user_cryptodev.c
Signature · 1 line
2.25.1
PATCH v4 1/6 crypto/virtio: add asymmetric RSA support
Asymmetric RSA operations (SIGN, VERIFY, ENCRYPT and DECRYPT) are supported in virtio PMD.
---
Depends-on: series-34682 ("vhost: add RSA support")
--- .../virtio/virtio_crypto_capabilities.h | 19 + drivers/crypto/virtio/virtio_cryptodev.c | 347 +++++++++++++++--- drivers/crypto/virtio/virtio_cryptodev.h | 2 + drivers/crypto/virtio/virtio_rxtx.c | 243 ++++++++++-- lib/cryptodev/cryptodev_pmd.h | 6 + 5 files changed, 539 insertions(+), 78 deletions(-)
drivers/crypto/virtio/virtio_crypto_capabilities.h +19 -0
@@ -48,4 +48,23 @@ }, } \ } +#define VIRTIO_ASYM_CAPABILITIES \ + { /* RSA */ \ + .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC, \ + {.asym = { \ + .xform_capa = { \ + .xform_type = RTE_CRYPTO_ASYM_XFORM_RSA, \ + .op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) | \ + (1 << RTE_CRYPTO_ASYM_OP_VERIFY) | \ + (1 << RTE_CRYPTO_ASYM_OP_ENCRYPT) | \ + (1 << RTE_CRYPTO_ASYM_OP_DECRYPT)), \ + {.modlen = { \ + .min = 1, \ + .max = 1024, \ + .increment = 1 \ + }, } \ + } \ + }, } \ + } +#endif /* _VIRTIO_CRYPTO_CAPABILITIES_H_ */
drivers/crypto/virtio/virtio_cryptodev.c +302 -45
444 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +2 -0
@@ -20,6 +20,8 @@#define VIRTIO_CRYPTO_MAX_KEY_SIZE 256 +#define VIRTIO_CRYPTO_MAX_CTRL_DATA 2048 +extern uint8_t cryptodev_virtio_driver_id;enum virtio_crypto_cmd_id {
drivers/crypto/virtio/virtio_rxtx.c +210 -33
285 lines not on this page · raw message
lib/cryptodev/cryptodev_pmd.h +6 -0
@@ -715,6 +715,12 @@ struct rte_cryptodev_asym_session {uint8_t sess_private_data[]; }; +/** +* Helper macro to get session private data +*/ +#define CRYPTODEV_GET_ASYM_SESS_PRIV (s) \ + ((void *)(((struct rte_cryptodev_asym_session *)s)->sess_private_data)) + #ifdef __cplusplus }#endif
Signature · 1 line
2.25.1
PATCH v4 2/6 crypto/virtio: refactor queue operations
In reply to Gowrishankar MuthukrishnanMove existing control queue operations into a common place that would be shared with other virtio type of devices.
---
Depends-on: series-34682 ("vhost: add RSA support")
--- drivers/crypto/virtio/meson.build | 1 + drivers/crypto/virtio/virtio_crypto_algs.h | 2 +- drivers/crypto/virtio/virtio_cryptodev.c | 563 ++++++++------------- drivers/crypto/virtio/virtio_cvq.c | 129 +++++ drivers/crypto/virtio/virtio_cvq.h | 33 ++ drivers/crypto/virtio/virtio_pci.h | 6 +- drivers/crypto/virtio/virtio_ring.h | 12 +- drivers/crypto/virtio/virtio_rxtx.c | 42 +- drivers/crypto/virtio/virtio_rxtx.h | 13 + drivers/crypto/virtio/virtqueue.c | 191 ++++++- drivers/crypto/virtio/virtqueue.h | 89 +++- 11 files changed, 691 insertions(+), 390 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_cvq.c create mode 100644 drivers/crypto/virtio/virtio_cvq.h create mode 100644 drivers/crypto/virtio/virtio_rxtx.h
drivers/crypto/virtio/meson.build +1 -0
@@ -11,6 +11,7 @@ includes += include_directories('../../../lib/vhost') deps += 'bus_pci' sources = files( 'virtio_cryptodev.c', + 'virtio_cvq.c', 'virtio_pci.c', 'virtio_rxtx.c', 'virtqueue.c',
drivers/crypto/virtio/virtio_crypto_algs.h +1 -1
@@ -22,7 +22,7 @@ struct virtio_crypto_session { phys_addr_t phys_addr; } aad; -struct virtio_crypto_op_ctrl_req ctrl; +struct virtio_pmd_ctrl ctrl; };#endif /* _VIRTIO_CRYPTO_ALGS_H_ */
drivers/crypto/virtio/virtio_cryptodev.c +217 -346
768 lines not on this page · raw message
drivers/crypto/virtio/virtio_cvq.c new file +129 -0
129 lines not on this page · raw message
drivers/crypto/virtio/virtio_cvq.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Marvell +*/ + +#ifndef _VIRTIO_CVQ_H_ +#define _VIRTIO_CVQ_H_ + +#include <rte_spinlock.h> +#include <virtio_crypto.h> + +#include "virtio_cryptodev.h" + +struct virtqueue ; + +struct virtcrypto_ctl { +const struct rte_memzone *hdr_mz;/**< memzone to populate hdr. */ +rte_iova_t hdr_mem;/**< hdr for each xmit packet */ +rte_spinlock_t lock;/**< spinlock for control queue. */ +void (*notify_queue)(struct virtqueue *vq,void *cookie);/**< notify ops. */ +void *notify_cookie;/**< cookie for notify ops */ +}; + +struct virtio_pmd_ctrl { +struct virtio_crypto_op_ctrl_req hdr; +struct virtio_crypto_session_input input; +uint8_t data[VIRTIO_CRYPTO_MAX_CTRL_DATA ]; +}; + +int +virtio_crypto_send_command (struct virtcrypto_ctl *cvq,struct virtio_pmd_ctrl *ctrl, +int *dlen,int pkt_num); + +#endif /* _VIRTIO_CVQ_H_ */
drivers/crypto/virtio/virtio_pci.h +4 -2
@@ -176,8 +176,7 @@ struct virtio_pci_ops { };struct virtio_crypto_hw { -/* control queue */ -struct virtqueue *cvq; +struct virtqueue **vqs;uint16_t dev_id;uint16_t max_dataqueues;uint64_t req_guest_features;
@@ -190,6 +189,9 @@ struct virtio_crypto_hw {struct virtio_pci_common_cfg *common_cfg;struct virtio_crypto_config *dev_cfg;const struct rte_cryptodev_capabilities *virtio_dev_capabilities; +uint8_t weak_barriers; +struct virtcrypto_ctl *cvq; +bool use_va; };/*
drivers/crypto/virtio/virtio_ring.h +10 -2
@@ -59,6 +59,7 @@ struct vring_used {struct vring {unsigned int num; +rte_iova_t desc_iova;struct vring_desc *desc;struct vring_avail *avail;struct vring_used *used;
@@ -111,17 +112,24 @@ vring_size(unsigned int num, unsigned long align) }static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p, -unsigned long align) +vring_init_split (struct vring *vr,uint8_t *p,rte_iova_t iova, +unsigned long align,unsigned int num) { vr->num = num; vr->desc = (struct vring_desc *) p; + vr->desc_iova = iova; vr->avail = (struct vring_avail *) (p + num *sizeof (struct vring_desc )); vr->used = (void *)RTE_ALIGN_CEIL ((uintptr_t )(&vr->avail->ring[num]), align); } +static inline void +vring_init (struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) +{ +vring_init_split (vr, p,0 , align, num); +} +/* * The following is used with VIRTIO_RING_F_EVENT_IDX. * Assuming a given event_idx value from the other size, if we have
drivers/crypto/virtio/virtio_rxtx.c +16 -26
111 lines not on this page · raw message
drivers/crypto/virtio/virtio_rxtx.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Marvell. +*/ + +#ifndef _VIRTIO_RXTX_H_ +#define _VIRTIO_RXTX_H_ + +struct virtcrypto_data { +const struct rte_memzone *hdr_mz;/**< memzone to populate hdr. */ +rte_iova_t hdr_mem;/**< hdr for each xmit packet */ +}; + +#endif /* _VIRTIO_RXTX_H_ */
drivers/crypto/virtio/virtqueue.c +188 -3
212 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h +79 -10
162 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v4 3/6 crypto/virtio: add packed ring support
In reply to Gowrishankar MuthukrishnanAdd packed ring support.
---
Depends-on: series-34682 ("vhost: add RSA support")
--- drivers/crypto/virtio/virtio_cryptodev.c | 125 +++++++ drivers/crypto/virtio/virtio_cryptodev.h | 13 +- drivers/crypto/virtio/virtio_cvq.c | 103 +++++- drivers/crypto/virtio/virtio_pci.h | 25 ++ drivers/crypto/virtio/virtio_ring.h | 59 ++- drivers/crypto/virtio/virtio_rxtx.c | 444 ++++++++++++++++++++++- drivers/crypto/virtio/virtqueue.c | 50 ++- drivers/crypto/virtio/virtqueue.h | 134 ++++++- 8 files changed, 924 insertions(+), 29 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +125 -0
@@ -869,6 +869,125 @@ virtio_crypto_clear_session(rte_free (ctrl); } +static void +virtio_crypto_clear_session_packed ( +struct rte_cryptodev *dev, +struct virtio_crypto_op_ctrl_req *ctrl) +{ +struct virtio_crypto_hw *hw; +struct virtqueue *vq; +struct vring_packed_desc *desc; +uint8_t *status; +uint8_t needed =1 ; +uint32_t head; +uint64_t malloc_phys_addr; +uint8_t len_inhdr =sizeof (struct virtio_crypto_inhdr ); +uint32_t len_op_ctrl_req =sizeof (struct virtio_crypto_op_ctrl_req ); +uint64_t session_id = ctrl->u.destroy_session.session_id; +uint16_t flags; +uint8_t nb_descs =0 ; + + hw = dev->data->dev_private; + vq =virtcrypto_cq_to_vq (hw->cvq); + head = vq->vq_avail_idx; + flags = vq->vq_packed.cached_flags; + +VIRTIO_CRYPTO_SESSION_LOG_INFO ("vq->vq_desc_head_idx = %d, " +"vq = %p" , vq->vq_desc_head_idx, vq); + +if (vq->vq_free_cnt < needed) { +VIRTIO_CRYPTO_SESSION_LOG_ERR ( +"vq->vq_free_cnt = %d is less than %d, " +"not enough" , vq->vq_free_cnt, needed); +return ; + } + + malloc_phys_addr =rte_malloc_virt2iova (ctrl); + +/* status part */ + status = &(((struct virtio_crypto_inhdr *) + ((uint8_t *)ctrl + len_op_ctrl_req))->status); + *status =VIRTIO_CRYPTO_ERR ; + +/* indirect desc vring part */ + desc = vq->vq_packed.ring.desc; + +/* ctrl request part */ + desc[head].addr = malloc_phys_addr; + desc[head].len = len_op_ctrl_req; + desc[head].flags =VRING_DESC_F_NEXT | vq->vq_packed.cached_flags; + vq->vq_free_cnt--; + nb_descs++; +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^=VRING_PACKED_DESC_F_AVAIL_USED ; + } + +/* status part */ + desc[vq->vq_avail_idx].addr = malloc_phys_addr + len_op_ctrl_req; + desc[vq->vq_avail_idx].len = len_inhdr; + desc[vq->vq_avail_idx].flags =VRING_DESC_F_WRITE ; + vq->vq_free_cnt--; + nb_descs++; +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^=VRING_PACKED_DESC_F_AVAIL_USED ; + } + +virtqueue_store_flags_packed (&desc[head],VRING_DESC_F_NEXT | flags, + vq->hw->weak_barriers); + +virtio_wmb (vq->hw->weak_barriers); +virtqueue_notify (vq); + +/* wait for used desc in virtqueue +* desc_is_used has a load-acquire or rte_io_rmb inside +*/ +rte_rmb (); +while (!desc_is_used (&desc[head], vq)) { +rte_rmb (); +usleep (100 ); + } + +/* now get used descriptors */ + vq->vq_free_cnt += nb_descs; + vq->vq_used_cons_idx += nb_descs; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +PMD_INIT_LOG (DEBUG ,"vq->vq_free_cnt=%d " +"vq->vq_queue_idx=%d " +"vq->vq_avail_idx=%d " +"vq->vq_used_cons_idx=%d " +"vq->vq_packed.cached_flags=0x%x " +"vq->vq_packed.used_wrap_counter=%d" , + vq->vq_free_cnt, + vq->vq_queue_index, + vq->vq_avail_idx, + vq->vq_used_cons_idx, + vq->vq_packed.cached_flags, + vq->vq_packed.used_wrap_counter); + +if (*status !=VIRTIO_CRYPTO_OK ) { +VIRTIO_CRYPTO_SESSION_LOG_ERR ("Close session failed " +"status=%" PRIu32", session_id=%" PRIu64"" , + *status, session_id); +rte_free (ctrl); +return ; + } + +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_free_cnt=%d " +"vq->vq_desc_head_idx=%d" , + vq->vq_free_cnt, vq->vq_desc_head_idx); + +VIRTIO_CRYPTO_SESSION_LOG_INFO ("Close session %" PRIu64" successfully " , + session_id); + +rte_free (ctrl); +} + static void virtio_crypto_sym_clear_session( struct rte_cryptodev *dev,
@@ -906,6 +1025,9 @@ virtio_crypto_sym_clear_session( ctrl->header.queue_id =0 ; ctrl->u.destroy_session.session_id = session->session_id; +if (vtpci_with_packed_queue (dev->data->dev_private)) +return virtio_crypto_clear_session_packed (dev, ctrl); +return virtio_crypto_clear_session (dev, ctrl); }
@@ -943,6 +1065,9 @@ virtio_crypto_asym_clear_session( ctrl->header.queue_id =0 ; ctrl->u.destroy_session.session_id = session->session_id; +if (vtpci_with_packed_queue (dev->data->dev_private)) +return virtio_crypto_clear_session_packed (dev, ctrl); +return virtio_crypto_clear_session (dev, ctrl); }
drivers/crypto/virtio/virtio_cryptodev.h +12 -1
@@ -10,13 +10,21 @@#include "virtio_ring.h" /* Features desired/implemented by this driver. */ -#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1) +#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1 | \ + 1ULL << VIRTIO_F_IN_ORDER | \ + 1ULL << VIRTIO_F_RING_PACKED | \ + 1ULL << VIRTIO_F_NOTIFICATION_DATA | \ + 1ULL << VIRTIO_RING_F_INDIRECT_DESC | \ + 1ULL << VIRTIO_F_ORDER_PLATFORM)#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7#define VIRTIO_CRYPTO_MAX_IV_SIZE 16 +#define VIRTIO_CRYPTO_MAX_MSG_SIZE 512 +#define VIRTIO_CRYPTO_MAX_SIGN_SIZE 512 +#define VIRTIO_CRYPTO_MAX_CIPHER_SIZE 1024#define VIRTIO_CRYPTO_MAX_KEY_SIZE 256
@@ -36,6 +44,9 @@ struct virtio_crypto_op_cookie {struct virtio_crypto_inhdr inhdr;struct vring_desc desc[NUM_ENTRY_VIRTIO_CRYPTO_OP ];uint8_t iv[VIRTIO_CRYPTO_MAX_IV_SIZE ]; +uint8_t message[VIRTIO_CRYPTO_MAX_MSG_SIZE ]; +uint8_t sign[VIRTIO_CRYPTO_MAX_SIGN_SIZE ]; +uint8_t cipher[VIRTIO_CRYPTO_MAX_CIPHER_SIZE ]; };/*
drivers/crypto/virtio/virtio_cvq.c +101 -2
115 lines not on this page · raw message
drivers/crypto/virtio/virtio_pci.h +25 -0
@@ -83,6 +83,25 @@ struct virtqueue;#define VIRTIO_F_VERSION_1 32#define VIRTIO_F_IOMMU_PLATFORM 33 +#define VIRTIO_F_RING_PACKED 34 + +/* +* Inorder feature indicates that all buffers are used by the device +* in the same order in which they have been made available. +*/ +#define VIRTIO_F_IN_ORDER 35 + +/* +* This feature indicates that memory accesses by the driver and the device +* are ordered in a way described by the platform. +*/ +#define VIRTIO_F_ORDER_PLATFORM 36 + +/* +* This feature indicates that the driver passes extra data (besides +* identifying the virtqueue) in its device notifications. +*/ +#define VIRTIO_F_NOTIFICATION_DATA 38/* The Guest publishes the used index for which it expects an interrupt * at the end of the avail ring. Host should ignore the avail->flags field.
@@ -230,6 +249,12 @@ vtpci_with_feature(struct virtio_crypto_hw *hw, uint64_t bit)return (hw->guest_features & (1ULL << bit)) !=0 ; } +static inline int +vtpci_with_packed_queue (struct virtio_crypto_hw *hw) +{ +return vtpci_with_feature (hw,VIRTIO_F_RING_PACKED ); +} +/* * Function declaration from virtio_pci.c */
drivers/crypto/virtio/virtio_ring.h +58 -1
86 lines not on this page · raw message
drivers/crypto/virtio/virtio_rxtx.c +433 -11
496 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.c +42 -8
84 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h +128 -6
175 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v4 4/6 crypto/virtio: add vDPA backend
In reply to Gowrishankar MuthukrishnanAdd vDPA backend to virtio_user crypto.
---
Depends-on: series-34682 ("vhost: add RSA support") v4:
- fixed CI issue.
--- drivers/crypto/virtio/meson.build | 7 + drivers/crypto/virtio/virtio_cryptodev.c | 57 +- drivers/crypto/virtio/virtio_cryptodev.h | 3 + drivers/crypto/virtio/virtio_logs.h | 6 +- drivers/crypto/virtio/virtio_pci.h | 7 + drivers/crypto/virtio/virtio_ring.h | 6 - drivers/crypto/virtio/virtio_user/vhost.h | 90 +++ .../crypto/virtio/virtio_user/vhost_vdpa.c | 710 +++++++++++++++++ .../virtio/virtio_user/virtio_user_dev.c | 749 ++++++++++++++++++ .../virtio/virtio_user/virtio_user_dev.h | 85 ++ drivers/crypto/virtio/virtio_user_cryptodev.c | 575 ++++++++++++++ 11 files changed, 2265 insertions(+), 30 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_user/vhost.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost_vdpa.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.h create mode 100644 drivers/crypto/virtio/virtio_user_cryptodev.c
drivers/crypto/virtio/meson.build +7 -0
@@ -16,3 +16,10 @@ sources = files( 'virtio_rxtx.c', 'virtqueue.c', ) + +if is_linux + sources += files('virtio_user_cryptodev.c', + 'virtio_user/vhost_vdpa.c', + 'virtio_user/virtio_user_dev.c') + deps += ['bus_vdev'] +endif
drivers/crypto/virtio/virtio_cryptodev.c +35 -22
75 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +3 -0
@@ -76,4 +76,7 @@ uint16_t virtio_crypto_pkt_rx_burst(void *tx_queue,struct rte_crypto_op **tx_pkts, uint16_t nb_pkts); +int crypto_virtio_dev_init (struct rte_cryptodev *cryptodev,uint64_t features, +struct rte_pci_device *pci_dev); +#endif /* _VIRTIO_CRYPTODEV_H_ */
drivers/crypto/virtio/virtio_logs.h +4 -2
@@ -15,8 +15,10 @@ extern int virtio_crypto_logtype_init;#define PMD_INIT_FUNC_TRACE () PMD_INIT_LOG(DEBUG, " >>") -extern int virtio_crypto_logtype_init; -#define RTE_LOGTYPE_VIRTIO_CRYPTO_INIT virtio_crypto_logtype_init +extern int virtio_crypto_logtype_driver; +#define RTE_LOGTYPE_VIRTIO_CRYPTO_DRIVER virtio_crypto_logtype_driver +#define PMD_DRV_LOG (level, ...) \ + RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_DRIVER, "%s(): ", __func__, __VA_ARGS__)#define VIRTIO_CRYPTO_INIT_LOG_IMPL (level, ...) \ RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_INIT, "%s(): ", __func__, __VA_ARGS__)
drivers/crypto/virtio/virtio_pci.h +7 -0
@@ -20,6 +20,9 @@ struct virtqueue;#define VIRTIO_CRYPTO_PCI_VENDORID 0x1AF4#define VIRTIO_CRYPTO_PCI_DEVICEID 0x1054 +/* VirtIO device IDs. */ +#define VIRTIO_ID_CRYPTO 20 +/* VirtIO ABI version, this must match exactly. */ #define VIRTIO_PCI_ABI_VERSION 0
@@ -56,8 +59,12 @@ struct virtqueue;#define VIRTIO_CONFIG_STATUS_DRIVER 0x02#define VIRTIO_CONFIG_STATUS_DRIVER_OK 0x04#define VIRTIO_CONFIG_STATUS_FEATURES_OK 0x08 +#define VIRTIO_CONFIG_STATUS_DEV_NEED_RESET 0x40#define VIRTIO_CONFIG_STATUS_FAILED 0x80 +/* The alignment to use between consumer and producer parts of vring. */ +#define VIRTIO_VRING_ALIGN 4096 +/* * Each virtqueue indirect descriptor list must be physically contiguous. * To allow us to malloc(9) each list individually, limit the number
drivers/crypto/virtio/virtio_ring.h +0 -6
@@ -181,12 +181,6 @@ vring_init_packed(struct vring_packed *vr, uint8_t *p, rte_iova_t iova, sizeof(struct vring_packed_desc_event)), align); } -static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) -{ -vring_init_split (vr, p,0 , align, num); -} -/* * The following is used with VIRTIO_RING_F_EVENT_IDX. * Assuming a given event_idx value from the other size, if we have
drivers/crypto/virtio/virtio_user/vhost.h new file +90 -0
90 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/vhost_vdpa.c new file +710 -0
710 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/virtio_user_dev.c new file +749 -0
749 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/virtio_user_dev.h new file +85 -0
85 lines not on this page · raw message
drivers/crypto/virtio/virtio_user_cryptodev.c new file +575 -0
575 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v4 5/6 test/crypto: add asymmetric tests for virtio PMD
In reply to Gowrishankar MuthukrishnanAdd asymmetric tests for Virtio PMD.
--- app/test/test_cryptodev_asym.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
app/test/test_cryptodev_asym.c +28 -0
@@ -4023,6 +4023,19 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite = { } }; +static struct unit_test_suite cryptodev_virtio_asym_testsuite = { + .suite_name ="Crypto Device VIRTIO ASYM Unit Test Suite" , + .setup = testsuite_setup, + .teardown = testsuite_teardown, + .unit_test_cases = { +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, test_capability), +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, + test_rsa_sign_verify_crt), +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec_crt), +TEST_CASES_END ()/**< NULL terminate unit test array */ + } +}; +static int test_cryptodev_openssl_asym (void ) {
@@ -4091,8 +4104,23 @@ test_cryptodev_cn10k_asym(void)return unit_test_suite_runner (&cryptodev_octeontx_asym_testsuite); } +static int +test_cryptodev_virtio_asym (void ) +{ + gbl_driver_id =rte_cryptodev_driver_id_get ( +RTE_STR (CRYPTODEV_NAME_VIRTIO_PMD )); +if (gbl_driver_id ==-1 ) { +RTE_LOG (ERR ,USER1 ,"virtio PMD must be loaded.\n" ); +return TEST_FAILED ; + } + +/* Use test suite registered for crypto_virtio PMD */ +return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); +} +REGISTER_DRIVER_TEST (cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);REGISTER_DRIVER_TEST (cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);REGISTER_DRIVER_TEST (cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);REGISTER_DRIVER_TEST (cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);REGISTER_DRIVER_TEST (cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym); +REGISTER_DRIVER_TEST (cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym);
Signature · 1 line
2.25.1
PATCH v4 6/6 test/crypto: add tests for virtio user PMD
In reply to Gowrishankar MuthukrishnanReuse virtio_crypto tests for testing virtio_crypto_user PMD.
--- app/test/test_cryptodev.c | 7 +++++++ app/test/test_cryptodev.h | 1 + app/test/test_cryptodev_asym.c | 15 +++++++++++++++ 3 files changed, 23 insertions(+)
app/test/test_cryptodev.c +7 -0
@@ -19737,6 +19737,12 @@ test_cryptodev_virtio(void)return run_cryptodev_testsuite (RTE_STR (CRYPTODEV_NAME_VIRTIO_PMD )); } +static int +test_cryptodev_virtio_user (void ) +{ +return run_cryptodev_testsuite (RTE_STR (CRYPTODEV_NAME_VIRTIO_USER_PMD )); +} +static int test_cryptodev_aesni_mb (void ) {
@@ -20074,6 +20080,7 @@ REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);REGISTER_DRIVER_TEST (cryptodev_ccp_autotest, test_cryptodev_ccp);REGISTER_DRIVER_TEST (cryptodev_uadk_autotest, test_cryptodev_uadk);REGISTER_DRIVER_TEST (cryptodev_virtio_autotest, test_cryptodev_virtio); +REGISTER_DRIVER_TEST (cryptodev_virtio_user_autotest, test_cryptodev_virtio_user);REGISTER_DRIVER_TEST (cryptodev_octeontx_autotest, test_cryptodev_octeontx);REGISTER_DRIVER_TEST (cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);REGISTER_DRIVER_TEST (cryptodev_nitrox_autotest, test_cryptodev_nitrox);
app/test/test_cryptodev.h +1 -0
@@ -64,6 +64,7 @@#define CRYPTODEV_NAME_MVSAM_PMD crypto_mvsam#define CRYPTODEV_NAME_CCP_PMD crypto_ccp#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +#define CRYPTODEV_NAME_VIRTIO_USER_PMD crypto_virtio_user#define CRYPTODEV_NAME_OCTEONTX_SYM_PMD crypto_octeontx#define CRYPTODEV_NAME_CAAM_JR_PMD crypto_caam_jr#define CRYPTODEV_NAME_NITROX_PMD crypto_nitrox_sym
app/test/test_cryptodev_asym.c +15 -0
@@ -4118,9 +4118,24 @@ test_cryptodev_virtio_asym(void)return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); } +static int +test_cryptodev_virtio_user_asym (void ) +{ + gbl_driver_id =rte_cryptodev_driver_id_get ( +RTE_STR (CRYPTODEV_NAME_VIRTIO_USER_PMD )); +if (gbl_driver_id ==-1 ) { +RTE_LOG (ERR ,USER1 ,"virtio user PMD must be loaded.\n" ); +return TEST_FAILED ; + } + +/* Use test suite registered for crypto_virtio_user PMD */ +return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); +} +REGISTER_DRIVER_TEST (cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);REGISTER_DRIVER_TEST (cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);REGISTER_DRIVER_TEST (cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);REGISTER_DRIVER_TEST (cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);REGISTER_DRIVER_TEST (cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym);REGISTER_DRIVER_TEST (cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym); +REGISTER_DRIVER_TEST (cryptodev_virtio_user_asym_autotest, test_cryptodev_virtio_user_asym);
Signature · 1 line
2.25.1
RE: [v4 0/6] crypto/virtio: enhancements for RSA and vDPA
In reply to Gowrishankar MuthukrishnanQuoted 50 lines
-----Original Message-----
From: Gowrishankar Muthukrishnan <[email protected]>
Sent: Saturday, February 22, 2025 2:47 PM
To: [email protected]
Cc: Anoob Joseph <[email protected]>; Akhil Goyal <[email protected]>; Gowrishankar Muthukrishnan <[email protected]>
Subject: [v4 0/6]crypto/virtio: enhancements for RSA and vDPAThis patch series enhances virtio crypto PMD to:
* support RSA
* support packed virtio ring
* support vDPA backendv4:
- CI issue fixed.Depends-on: series-34682 ("vhost: add RSA support")
Gowrishankar Muthukrishnan (6):
crypto/virtio: add asymmetric RSA supportcrypto/virtio: refactor queue operationscrypto/virtio: add packed ring supportcrypto/virtio: add vDPA backend test/crypto: add asymmetric tests for virtio PMD test/crypto: add tests for virtio user PMDapp/test/test_cryptodev.c | 7 + app/test/test_cryptodev.h | 1 + app/test/test_cryptodev_asym.c | 43 + drivers/crypto/virtio/meson.build | 8 + drivers/crypto/virtio/virtio_crypto_algs.h | 2 +- .../virtio/virtio_crypto_capabilities.h | 19 + drivers/crypto/virtio/virtio_cryptodev.c | 1060 +++++++++++------ drivers/crypto/virtio/virtio_cryptodev.h | 18 +- drivers/crypto/virtio/virtio_cvq.c | 228 ++++ drivers/crypto/virtio/virtio_cvq.h | 33 + drivers/crypto/virtio/virtio_logs.h | 6 +- drivers/crypto/virtio/virtio_pci.h | 38 +- drivers/crypto/virtio/virtio_ring.h | 65 +- drivers/crypto/virtio/virtio_rxtx.c | 721 ++++++++++- drivers/crypto/virtio/virtio_rxtx.h | 13 + drivers/crypto/virtio/virtio_user/vhost.h | 90 ++ .../crypto/virtio/virtio_user/vhost_vdpa.c | 710 +++++++++++ .../virtio/virtio_user/virtio_user_dev.c | 749 ++++++++++++ .../virtio/virtio_user/virtio_user_dev.h | 85 ++ drivers/crypto/virtio/virtio_user_cryptodev.c | 575 +++++++++ drivers/crypto/virtio/virtqueue.c | 229 +++- drivers/crypto/virtio/virtqueue.h | 221 +++- lib/cryptodev/cryptodev_pmd.h | 6 + 23 files changed, 4435 insertions(+), 492 deletions(-)
Quoted 9 lines
create mode 100644 drivers/crypto/virtio/virtio_cvq.c create mode 100644 drivers/crypto/virtio/virtio_cvq.h create mode 100644 drivers/crypto/virtio/virtio_rxtx.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost_vdpa.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.h create mode 100644 drivers/crypto/virtio/virtio_user_cryptodev.c
Add documentation and release notes updates.
v5 cover crypto/virtio: enhancements for RSA and vDPA
In reply to Gowrishankar MuthukrishnanThis patch series enhances virtio crypto PMD to:
* support RSA
* support packed virtio ring
* support vDPA backend
Depends-on: patch-152109 ("vhost: support asymmetric RSA crypto ops")
Gowrishankar Muthukrishnan (6):
crypto/virtio: add asymmetric RSA support crypto/virtio: refactor queue operations crypto/virtio: add packed ring support crypto/virtio: add vDPA backend test/crypto: add asymmetric tests for virtio PMD test/crypto: add tests for virtio user PMD
app/test/test_cryptodev.c | 7 + app/test/test_cryptodev.h | 1 + app/test/test_cryptodev_asym.c | 43 + doc/guides/cryptodevs/features/virtio.ini | 4 + doc/guides/rel_notes/release_25_03.rst | 4 + drivers/crypto/virtio/meson.build | 8 + drivers/crypto/virtio/virtio_crypto_algs.h | 2 +- .../virtio/virtio_crypto_capabilities.h | 19 + drivers/crypto/virtio/virtio_cryptodev.c | 1060 +++++++++++------ drivers/crypto/virtio/virtio_cryptodev.h | 18 +- drivers/crypto/virtio/virtio_cvq.c | 228 ++++ drivers/crypto/virtio/virtio_cvq.h | 33 + drivers/crypto/virtio/virtio_logs.h | 6 +- drivers/crypto/virtio/virtio_pci.h | 38 +- drivers/crypto/virtio/virtio_ring.h | 65 +- drivers/crypto/virtio/virtio_rxtx.c | 725 ++++++++++- drivers/crypto/virtio/virtio_rxtx.h | 13 + drivers/crypto/virtio/virtio_user/vhost.h | 90 ++ .../crypto/virtio/virtio_user/vhost_vdpa.c | 710 +++++++++++ .../virtio/virtio_user/virtio_user_dev.c | 749 ++++++++++++ .../virtio/virtio_user/virtio_user_dev.h | 85 ++ drivers/crypto/virtio/virtio_user_cryptodev.c | 575 +++++++++ drivers/crypto/virtio/virtqueue.c | 229 +++- drivers/crypto/virtio/virtqueue.h | 221 +++- lib/cryptodev/cryptodev_pmd.h | 6 + 25 files changed, 4447 insertions(+), 492 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_cvq.c create mode 100644 drivers/crypto/virtio/virtio_cvq.h create mode 100644 drivers/crypto/virtio/virtio_rxtx.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost_vdpa.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.h create mode 100644 drivers/crypto/virtio/virtio_user_cryptodev.c
Signature · 1 line
2.25.1
PATCH v5 1/6 crypto/virtio: add asymmetric RSA support
Asymmetric RSA operations (SIGN, VERIFY, ENCRYPT and DECRYPT) are supported in virtio PMD.
---
Depends-on: patch-152109 ("vhost: support asymmetric RSA crypto ops")
v5:
- fixed asym enqueue xmit func for correct head idx.
- release notes updated.
--- doc/guides/cryptodevs/features/virtio.ini | 4 + doc/guides/rel_notes/release_25_03.rst | 4 + .../virtio/virtio_crypto_capabilities.h | 19 + drivers/crypto/virtio/virtio_cryptodev.c | 347 +++++++++++++++--- drivers/crypto/virtio/virtio_cryptodev.h | 2 + drivers/crypto/virtio/virtio_rxtx.c | 247 +++++++++++-- lib/cryptodev/cryptodev_pmd.h | 6 + 7 files changed, 551 insertions(+), 78 deletions(-)
doc/guides/cryptodevs/features/virtio.ini +4 -0
@@ -4,8 +4,11 @@ ; [Features] Symmetric crypto = Y +Asymmetric crypto = Y Sym operation chaining = Y OOP LB In LB Out = Y +RSA PRIV OP KEY EXP = Y +RSA PRIV OP KEY QT = Y ; ; Supported crypto algorithms of the 'virtio' crypto driver.
@@ -30,6 +33,7 @@ SHA1 HMAC = Y ; Supported Asymmetric algorithms of the 'virtio' crypto driver. ; [Asymmetric] +RSA = Y ; ; Supported Operating systems of the 'virtio' crypto driver.
doc/guides/rel_notes/release_25_03.rst +4 -0
@@ -155,6 +155,10 @@ New Features Updated vhost library to support RSA crypto operations. +* **Updated virtio crypto driver.** + + Updated virtio crypto driver to support RSA crypto operations. + Removed Items -------------
drivers/crypto/virtio/virtio_crypto_capabilities.h +19 -0
@@ -48,4 +48,23 @@ }, } \ } +#define VIRTIO_ASYM_CAPABILITIES \ + { /* RSA */ \ + .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC, \ + {.asym = { \ + .xform_capa = { \ + .xform_type = RTE_CRYPTO_ASYM_XFORM_RSA, \ + .op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) | \ + (1 << RTE_CRYPTO_ASYM_OP_VERIFY) | \ + (1 << RTE_CRYPTO_ASYM_OP_ENCRYPT) | \ + (1 << RTE_CRYPTO_ASYM_OP_DECRYPT)), \ + {.modlen = { \ + .min = 1, \ + .max = 1024, \ + .increment = 1 \ + }, } \ + } \ + }, } \ + } +#endif /* _VIRTIO_CRYPTO_CAPABILITIES_H_ */
drivers/crypto/virtio/virtio_cryptodev.c +302 -45
444 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +2 -0
@@ -20,6 +20,8 @@#define VIRTIO_CRYPTO_MAX_KEY_SIZE 256 +#define VIRTIO_CRYPTO_MAX_CTRL_DATA 2048 +extern uint8_t cryptodev_virtio_driver_id;enum virtio_crypto_cmd_id {
drivers/crypto/virtio/virtio_rxtx.c +214 -33
289 lines not on this page · raw message
lib/cryptodev/cryptodev_pmd.h +6 -0
@@ -715,6 +715,12 @@ struct rte_cryptodev_asym_session {uint8_t sess_private_data[]; }; +/** +* Helper macro to get session private data +*/ +#define CRYPTODEV_GET_ASYM_SESS_PRIV (s) \ + ((void *)(((struct rte_cryptodev_asym_session *)s)->sess_private_data)) + #ifdef __cplusplus }#endif
Signature · 1 line
2.25.1
PATCH v5 2/6 crypto/virtio: refactor queue operations
In reply to Gowrishankar MuthukrishnanMove existing control queue operations into a common place that would be shared with other virtio type of devices.
--- drivers/crypto/virtio/meson.build | 1 + drivers/crypto/virtio/virtio_crypto_algs.h | 2 +- drivers/crypto/virtio/virtio_cryptodev.c | 563 ++++++++------------- drivers/crypto/virtio/virtio_cvq.c | 129 +++++ drivers/crypto/virtio/virtio_cvq.h | 33 ++ drivers/crypto/virtio/virtio_pci.h | 6 +- drivers/crypto/virtio/virtio_ring.h | 12 +- drivers/crypto/virtio/virtio_rxtx.c | 44 +- drivers/crypto/virtio/virtio_rxtx.h | 13 + drivers/crypto/virtio/virtqueue.c | 191 ++++++- drivers/crypto/virtio/virtqueue.h | 89 +++- 11 files changed, 692 insertions(+), 391 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_cvq.c create mode 100644 drivers/crypto/virtio/virtio_cvq.h create mode 100644 drivers/crypto/virtio/virtio_rxtx.h
drivers/crypto/virtio/meson.build +1 -0
@@ -11,6 +11,7 @@ includes += include_directories('../../../lib/vhost') deps += 'bus_pci' sources = files( 'virtio_cryptodev.c', + 'virtio_cvq.c', 'virtio_pci.c', 'virtio_rxtx.c', 'virtqueue.c',
drivers/crypto/virtio/virtio_crypto_algs.h +1 -1
@@ -22,7 +22,7 @@ struct virtio_crypto_session { phys_addr_t phys_addr; } aad; -struct virtio_crypto_op_ctrl_req ctrl; +struct virtio_pmd_ctrl ctrl; };#endif /* _VIRTIO_CRYPTO_ALGS_H_ */
drivers/crypto/virtio/virtio_cryptodev.c +217 -346
768 lines not on this page · raw message
drivers/crypto/virtio/virtio_cvq.c new file +129 -0
129 lines not on this page · raw message
drivers/crypto/virtio/virtio_cvq.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Marvell +*/ + +#ifndef _VIRTIO_CVQ_H_ +#define _VIRTIO_CVQ_H_ + +#include <rte_spinlock.h> +#include <virtio_crypto.h> + +#include "virtio_cryptodev.h" + +struct virtqueue ; + +struct virtcrypto_ctl { +const struct rte_memzone *hdr_mz;/**< memzone to populate hdr. */ +rte_iova_t hdr_mem;/**< hdr for each xmit packet */ +rte_spinlock_t lock;/**< spinlock for control queue. */ +void (*notify_queue)(struct virtqueue *vq,void *cookie);/**< notify ops. */ +void *notify_cookie;/**< cookie for notify ops */ +}; + +struct virtio_pmd_ctrl { +struct virtio_crypto_op_ctrl_req hdr; +struct virtio_crypto_session_input input; +uint8_t data[VIRTIO_CRYPTO_MAX_CTRL_DATA ]; +}; + +int +virtio_crypto_send_command (struct virtcrypto_ctl *cvq,struct virtio_pmd_ctrl *ctrl, +int *dlen,int pkt_num); + +#endif /* _VIRTIO_CVQ_H_ */
drivers/crypto/virtio/virtio_pci.h +4 -2
@@ -176,8 +176,7 @@ struct virtio_pci_ops { };struct virtio_crypto_hw { -/* control queue */ -struct virtqueue *cvq; +struct virtqueue **vqs;uint16_t dev_id;uint16_t max_dataqueues;uint64_t req_guest_features;
@@ -190,6 +189,9 @@ struct virtio_crypto_hw {struct virtio_pci_common_cfg *common_cfg;struct virtio_crypto_config *dev_cfg;const struct rte_cryptodev_capabilities *virtio_dev_capabilities; +uint8_t weak_barriers; +struct virtcrypto_ctl *cvq; +bool use_va; };/*
drivers/crypto/virtio/virtio_ring.h +10 -2
@@ -59,6 +59,7 @@ struct vring_used {struct vring {unsigned int num; +rte_iova_t desc_iova;struct vring_desc *desc;struct vring_avail *avail;struct vring_used *used;
@@ -111,17 +112,24 @@ vring_size(unsigned int num, unsigned long align) }static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p, -unsigned long align) +vring_init_split (struct vring *vr,uint8_t *p,rte_iova_t iova, +unsigned long align,unsigned int num) { vr->num = num; vr->desc = (struct vring_desc *) p; + vr->desc_iova = iova; vr->avail = (struct vring_avail *) (p + num *sizeof (struct vring_desc )); vr->used = (void *)RTE_ALIGN_CEIL ((uintptr_t )(&vr->avail->ring[num]), align); } +static inline void +vring_init (struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) +{ +vring_init_split (vr, p,0 , align, num); +} +/* * The following is used with VIRTIO_RING_F_EVENT_IDX. * Assuming a given event_idx value from the other size, if we have
drivers/crypto/virtio/virtio_rxtx.c +17 -27
119 lines not on this page · raw message
drivers/crypto/virtio/virtio_rxtx.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Marvell. +*/ + +#ifndef _VIRTIO_RXTX_H_ +#define _VIRTIO_RXTX_H_ + +struct virtcrypto_data { +const struct rte_memzone *hdr_mz;/**< memzone to populate hdr. */ +rte_iova_t hdr_mem;/**< hdr for each xmit packet */ +}; + +#endif /* _VIRTIO_RXTX_H_ */
drivers/crypto/virtio/virtqueue.c +188 -3
212 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h +79 -10
162 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 3/6 crypto/virtio: add packed ring support
In reply to Gowrishankar MuthukrishnanAdd packed ring support.
--- drivers/crypto/virtio/virtio_cryptodev.c | 125 +++++++ drivers/crypto/virtio/virtio_cryptodev.h | 13 +- drivers/crypto/virtio/virtio_cvq.c | 103 +++++- drivers/crypto/virtio/virtio_pci.h | 25 ++ drivers/crypto/virtio/virtio_ring.h | 59 ++- drivers/crypto/virtio/virtio_rxtx.c | 444 ++++++++++++++++++++++- drivers/crypto/virtio/virtqueue.c | 50 ++- drivers/crypto/virtio/virtqueue.h | 134 ++++++- 8 files changed, 924 insertions(+), 29 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +125 -0
@@ -869,6 +869,125 @@ virtio_crypto_clear_session(rte_free (ctrl); } +static void +virtio_crypto_clear_session_packed ( +struct rte_cryptodev *dev, +struct virtio_crypto_op_ctrl_req *ctrl) +{ +struct virtio_crypto_hw *hw; +struct virtqueue *vq; +struct vring_packed_desc *desc; +uint8_t *status; +uint8_t needed =1 ; +uint32_t head; +uint64_t malloc_phys_addr; +uint8_t len_inhdr =sizeof (struct virtio_crypto_inhdr ); +uint32_t len_op_ctrl_req =sizeof (struct virtio_crypto_op_ctrl_req ); +uint64_t session_id = ctrl->u.destroy_session.session_id; +uint16_t flags; +uint8_t nb_descs =0 ; + + hw = dev->data->dev_private; + vq =virtcrypto_cq_to_vq (hw->cvq); + head = vq->vq_avail_idx; + flags = vq->vq_packed.cached_flags; + +VIRTIO_CRYPTO_SESSION_LOG_INFO ("vq->vq_desc_head_idx = %d, " +"vq = %p" , vq->vq_desc_head_idx, vq); + +if (vq->vq_free_cnt < needed) { +VIRTIO_CRYPTO_SESSION_LOG_ERR ( +"vq->vq_free_cnt = %d is less than %d, " +"not enough" , vq->vq_free_cnt, needed); +return ; + } + + malloc_phys_addr =rte_malloc_virt2iova (ctrl); + +/* status part */ + status = &(((struct virtio_crypto_inhdr *) + ((uint8_t *)ctrl + len_op_ctrl_req))->status); + *status =VIRTIO_CRYPTO_ERR ; + +/* indirect desc vring part */ + desc = vq->vq_packed.ring.desc; + +/* ctrl request part */ + desc[head].addr = malloc_phys_addr; + desc[head].len = len_op_ctrl_req; + desc[head].flags =VRING_DESC_F_NEXT | vq->vq_packed.cached_flags; + vq->vq_free_cnt--; + nb_descs++; +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^=VRING_PACKED_DESC_F_AVAIL_USED ; + } + +/* status part */ + desc[vq->vq_avail_idx].addr = malloc_phys_addr + len_op_ctrl_req; + desc[vq->vq_avail_idx].len = len_inhdr; + desc[vq->vq_avail_idx].flags =VRING_DESC_F_WRITE ; + vq->vq_free_cnt--; + nb_descs++; +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^=VRING_PACKED_DESC_F_AVAIL_USED ; + } + +virtqueue_store_flags_packed (&desc[head],VRING_DESC_F_NEXT | flags, + vq->hw->weak_barriers); + +virtio_wmb (vq->hw->weak_barriers); +virtqueue_notify (vq); + +/* wait for used desc in virtqueue +* desc_is_used has a load-acquire or rte_io_rmb inside +*/ +rte_rmb (); +while (!desc_is_used (&desc[head], vq)) { +rte_rmb (); +usleep (100 ); + } + +/* now get used descriptors */ + vq->vq_free_cnt += nb_descs; + vq->vq_used_cons_idx += nb_descs; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +PMD_INIT_LOG (DEBUG ,"vq->vq_free_cnt=%d " +"vq->vq_queue_idx=%d " +"vq->vq_avail_idx=%d " +"vq->vq_used_cons_idx=%d " +"vq->vq_packed.cached_flags=0x%x " +"vq->vq_packed.used_wrap_counter=%d" , + vq->vq_free_cnt, + vq->vq_queue_index, + vq->vq_avail_idx, + vq->vq_used_cons_idx, + vq->vq_packed.cached_flags, + vq->vq_packed.used_wrap_counter); + +if (*status !=VIRTIO_CRYPTO_OK ) { +VIRTIO_CRYPTO_SESSION_LOG_ERR ("Close session failed " +"status=%" PRIu32", session_id=%" PRIu64"" , + *status, session_id); +rte_free (ctrl); +return ; + } + +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_free_cnt=%d " +"vq->vq_desc_head_idx=%d" , + vq->vq_free_cnt, vq->vq_desc_head_idx); + +VIRTIO_CRYPTO_SESSION_LOG_INFO ("Close session %" PRIu64" successfully " , + session_id); + +rte_free (ctrl); +} + static void virtio_crypto_sym_clear_session( struct rte_cryptodev *dev,
@@ -906,6 +1025,9 @@ virtio_crypto_sym_clear_session( ctrl->header.queue_id =0 ; ctrl->u.destroy_session.session_id = session->session_id; +if (vtpci_with_packed_queue (dev->data->dev_private)) +return virtio_crypto_clear_session_packed (dev, ctrl); +return virtio_crypto_clear_session (dev, ctrl); }
@@ -943,6 +1065,9 @@ virtio_crypto_asym_clear_session( ctrl->header.queue_id =0 ; ctrl->u.destroy_session.session_id = session->session_id; +if (vtpci_with_packed_queue (dev->data->dev_private)) +return virtio_crypto_clear_session_packed (dev, ctrl); +return virtio_crypto_clear_session (dev, ctrl); }
drivers/crypto/virtio/virtio_cryptodev.h +12 -1
@@ -10,13 +10,21 @@#include "virtio_ring.h" /* Features desired/implemented by this driver. */ -#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1) +#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1 | \ + 1ULL << VIRTIO_F_IN_ORDER | \ + 1ULL << VIRTIO_F_RING_PACKED | \ + 1ULL << VIRTIO_F_NOTIFICATION_DATA | \ + 1ULL << VIRTIO_RING_F_INDIRECT_DESC | \ + 1ULL << VIRTIO_F_ORDER_PLATFORM)#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7#define VIRTIO_CRYPTO_MAX_IV_SIZE 16 +#define VIRTIO_CRYPTO_MAX_MSG_SIZE 512 +#define VIRTIO_CRYPTO_MAX_SIGN_SIZE 512 +#define VIRTIO_CRYPTO_MAX_CIPHER_SIZE 1024#define VIRTIO_CRYPTO_MAX_KEY_SIZE 256
@@ -36,6 +44,9 @@ struct virtio_crypto_op_cookie {struct virtio_crypto_inhdr inhdr;struct vring_desc desc[NUM_ENTRY_VIRTIO_CRYPTO_OP ];uint8_t iv[VIRTIO_CRYPTO_MAX_IV_SIZE ]; +uint8_t message[VIRTIO_CRYPTO_MAX_MSG_SIZE ]; +uint8_t sign[VIRTIO_CRYPTO_MAX_SIGN_SIZE ]; +uint8_t cipher[VIRTIO_CRYPTO_MAX_CIPHER_SIZE ]; };/*
drivers/crypto/virtio/virtio_cvq.c +101 -2
115 lines not on this page · raw message
drivers/crypto/virtio/virtio_pci.h +25 -0
@@ -83,6 +83,25 @@ struct virtqueue;#define VIRTIO_F_VERSION_1 32#define VIRTIO_F_IOMMU_PLATFORM 33 +#define VIRTIO_F_RING_PACKED 34 + +/* +* Inorder feature indicates that all buffers are used by the device +* in the same order in which they have been made available. +*/ +#define VIRTIO_F_IN_ORDER 35 + +/* +* This feature indicates that memory accesses by the driver and the device +* are ordered in a way described by the platform. +*/ +#define VIRTIO_F_ORDER_PLATFORM 36 + +/* +* This feature indicates that the driver passes extra data (besides +* identifying the virtqueue) in its device notifications. +*/ +#define VIRTIO_F_NOTIFICATION_DATA 38/* The Guest publishes the used index for which it expects an interrupt * at the end of the avail ring. Host should ignore the avail->flags field.
@@ -230,6 +249,12 @@ vtpci_with_feature(struct virtio_crypto_hw *hw, uint64_t bit)return (hw->guest_features & (1ULL << bit)) !=0 ; } +static inline int +vtpci_with_packed_queue (struct virtio_crypto_hw *hw) +{ +return vtpci_with_feature (hw,VIRTIO_F_RING_PACKED ); +} +/* * Function declaration from virtio_pci.c */
drivers/crypto/virtio/virtio_ring.h +58 -1
86 lines not on this page · raw message
drivers/crypto/virtio/virtio_rxtx.c +433 -11
496 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.c +42 -8
84 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h +128 -6
175 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 4/6 crypto/virtio: add vDPA backend
In reply to Gowrishankar MuthukrishnanAdd vDPA backend to virtio_user crypto.
--- drivers/crypto/virtio/meson.build | 7 + drivers/crypto/virtio/virtio_cryptodev.c | 57 +- drivers/crypto/virtio/virtio_cryptodev.h | 3 + drivers/crypto/virtio/virtio_logs.h | 6 +- drivers/crypto/virtio/virtio_pci.h | 7 + drivers/crypto/virtio/virtio_ring.h | 6 - drivers/crypto/virtio/virtio_user/vhost.h | 90 +++ .../crypto/virtio/virtio_user/vhost_vdpa.c | 710 +++++++++++++++++ .../virtio/virtio_user/virtio_user_dev.c | 749 ++++++++++++++++++ .../virtio/virtio_user/virtio_user_dev.h | 85 ++ drivers/crypto/virtio/virtio_user_cryptodev.c | 575 ++++++++++++++ 11 files changed, 2265 insertions(+), 30 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_user/vhost.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost_vdpa.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.h create mode 100644 drivers/crypto/virtio/virtio_user_cryptodev.c
drivers/crypto/virtio/meson.build +7 -0
@@ -16,3 +16,10 @@ sources = files( 'virtio_rxtx.c', 'virtqueue.c', ) + +if is_linux + sources += files('virtio_user_cryptodev.c', + 'virtio_user/vhost_vdpa.c', + 'virtio_user/virtio_user_dev.c') + deps += ['bus_vdev'] +endif
drivers/crypto/virtio/virtio_cryptodev.c +35 -22
75 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +3 -0
@@ -76,4 +76,7 @@ uint16_t virtio_crypto_pkt_rx_burst(void *tx_queue,struct rte_crypto_op **tx_pkts, uint16_t nb_pkts); +int crypto_virtio_dev_init (struct rte_cryptodev *cryptodev,uint64_t features, +struct rte_pci_device *pci_dev); +#endif /* _VIRTIO_CRYPTODEV_H_ */
drivers/crypto/virtio/virtio_logs.h +4 -2
@@ -15,8 +15,10 @@ extern int virtio_crypto_logtype_init;#define PMD_INIT_FUNC_TRACE () PMD_INIT_LOG(DEBUG, " >>") -extern int virtio_crypto_logtype_init; -#define RTE_LOGTYPE_VIRTIO_CRYPTO_INIT virtio_crypto_logtype_init +extern int virtio_crypto_logtype_driver; +#define RTE_LOGTYPE_VIRTIO_CRYPTO_DRIVER virtio_crypto_logtype_driver +#define PMD_DRV_LOG (level, ...) \ + RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_DRIVER, "%s(): ", __func__, __VA_ARGS__)#define VIRTIO_CRYPTO_INIT_LOG_IMPL (level, ...) \ RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_INIT, "%s(): ", __func__, __VA_ARGS__)
drivers/crypto/virtio/virtio_pci.h +7 -0
@@ -20,6 +20,9 @@ struct virtqueue;#define VIRTIO_CRYPTO_PCI_VENDORID 0x1AF4#define VIRTIO_CRYPTO_PCI_DEVICEID 0x1054 +/* VirtIO device IDs. */ +#define VIRTIO_ID_CRYPTO 20 +/* VirtIO ABI version, this must match exactly. */ #define VIRTIO_PCI_ABI_VERSION 0
@@ -56,8 +59,12 @@ struct virtqueue;#define VIRTIO_CONFIG_STATUS_DRIVER 0x02#define VIRTIO_CONFIG_STATUS_DRIVER_OK 0x04#define VIRTIO_CONFIG_STATUS_FEATURES_OK 0x08 +#define VIRTIO_CONFIG_STATUS_DEV_NEED_RESET 0x40#define VIRTIO_CONFIG_STATUS_FAILED 0x80 +/* The alignment to use between consumer and producer parts of vring. */ +#define VIRTIO_VRING_ALIGN 4096 +/* * Each virtqueue indirect descriptor list must be physically contiguous. * To allow us to malloc(9) each list individually, limit the number
drivers/crypto/virtio/virtio_ring.h +0 -6
@@ -181,12 +181,6 @@ vring_init_packed(struct vring_packed *vr, uint8_t *p, rte_iova_t iova, sizeof(struct vring_packed_desc_event)), align); } -static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) -{ -vring_init_split (vr, p,0 , align, num); -} -/* * The following is used with VIRTIO_RING_F_EVENT_IDX. * Assuming a given event_idx value from the other size, if we have
drivers/crypto/virtio/virtio_user/vhost.h new file +90 -0
90 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/vhost_vdpa.c new file +710 -0
710 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/virtio_user_dev.c new file +749 -0
749 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/virtio_user_dev.h new file +85 -0
85 lines not on this page · raw message
drivers/crypto/virtio/virtio_user_cryptodev.c new file +575 -0
575 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 5/6 test/crypto: add asymmetric tests for virtio PMD
In reply to Gowrishankar MuthukrishnanAdd asymmetric tests for Virtio PMD.
--- app/test/test_cryptodev_asym.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
app/test/test_cryptodev_asym.c +28 -0
@@ -4023,6 +4023,19 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite = { } }; +static struct unit_test_suite cryptodev_virtio_asym_testsuite = { + .suite_name ="Crypto Device VIRTIO ASYM Unit Test Suite" , + .setup = testsuite_setup, + .teardown = testsuite_teardown, + .unit_test_cases = { +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, test_capability), +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, + test_rsa_sign_verify_crt), +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec_crt), +TEST_CASES_END ()/**< NULL terminate unit test array */ + } +}; +static int test_cryptodev_openssl_asym (void ) {
@@ -4091,8 +4104,23 @@ test_cryptodev_cn10k_asym(void)return unit_test_suite_runner (&cryptodev_octeontx_asym_testsuite); } +static int +test_cryptodev_virtio_asym (void ) +{ + gbl_driver_id =rte_cryptodev_driver_id_get ( +RTE_STR (CRYPTODEV_NAME_VIRTIO_PMD )); +if (gbl_driver_id ==-1 ) { +RTE_LOG (ERR ,USER1 ,"virtio PMD must be loaded.\n" ); +return TEST_FAILED ; + } + +/* Use test suite registered for crypto_virtio PMD */ +return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); +} +REGISTER_DRIVER_TEST (cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);REGISTER_DRIVER_TEST (cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);REGISTER_DRIVER_TEST (cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);REGISTER_DRIVER_TEST (cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);REGISTER_DRIVER_TEST (cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym); +REGISTER_DRIVER_TEST (cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym);
Signature · 1 line
2.25.1
PATCH v5 6/6 test/crypto: add tests for virtio user PMD
In reply to Gowrishankar MuthukrishnanReuse virtio_crypto tests for testing virtio_crypto_user PMD.
--- app/test/test_cryptodev.c | 7 +++++++ app/test/test_cryptodev.h | 1 + app/test/test_cryptodev_asym.c | 15 +++++++++++++++ 3 files changed, 23 insertions(+)
app/test/test_cryptodev.c +7 -0
@@ -19737,6 +19737,12 @@ test_cryptodev_virtio(void)return run_cryptodev_testsuite (RTE_STR (CRYPTODEV_NAME_VIRTIO_PMD )); } +static int +test_cryptodev_virtio_user (void ) +{ +return run_cryptodev_testsuite (RTE_STR (CRYPTODEV_NAME_VIRTIO_USER_PMD )); +} +static int test_cryptodev_aesni_mb (void ) {
@@ -20074,6 +20080,7 @@ REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);REGISTER_DRIVER_TEST (cryptodev_ccp_autotest, test_cryptodev_ccp);REGISTER_DRIVER_TEST (cryptodev_uadk_autotest, test_cryptodev_uadk);REGISTER_DRIVER_TEST (cryptodev_virtio_autotest, test_cryptodev_virtio); +REGISTER_DRIVER_TEST (cryptodev_virtio_user_autotest, test_cryptodev_virtio_user);REGISTER_DRIVER_TEST (cryptodev_octeontx_autotest, test_cryptodev_octeontx);REGISTER_DRIVER_TEST (cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);REGISTER_DRIVER_TEST (cryptodev_nitrox_autotest, test_cryptodev_nitrox);
app/test/test_cryptodev.h +1 -0
@@ -64,6 +64,7 @@#define CRYPTODEV_NAME_MVSAM_PMD crypto_mvsam#define CRYPTODEV_NAME_CCP_PMD crypto_ccp#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +#define CRYPTODEV_NAME_VIRTIO_USER_PMD crypto_virtio_user#define CRYPTODEV_NAME_OCTEONTX_SYM_PMD crypto_octeontx#define CRYPTODEV_NAME_CAAM_JR_PMD crypto_caam_jr#define CRYPTODEV_NAME_NITROX_PMD crypto_nitrox_sym
app/test/test_cryptodev_asym.c +15 -0
@@ -4118,9 +4118,24 @@ test_cryptodev_virtio_asym(void)return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); } +static int +test_cryptodev_virtio_user_asym (void ) +{ + gbl_driver_id =rte_cryptodev_driver_id_get ( +RTE_STR (CRYPTODEV_NAME_VIRTIO_USER_PMD )); +if (gbl_driver_id ==-1 ) { +RTE_LOG (ERR ,USER1 ,"virtio user PMD must be loaded.\n" ); +return TEST_FAILED ; + } + +/* Use test suite registered for crypto_virtio_user PMD */ +return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); +} +REGISTER_DRIVER_TEST (cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);REGISTER_DRIVER_TEST (cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);REGISTER_DRIVER_TEST (cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);REGISTER_DRIVER_TEST (cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);REGISTER_DRIVER_TEST (cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym);REGISTER_DRIVER_TEST (cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym); +REGISTER_DRIVER_TEST (cryptodev_virtio_user_asym_autotest, test_cryptodev_virtio_user_asym);
Signature · 1 line
2.25.1
v6 cover crypto/virtio: enhancements for RSA and vDPA
In reply to Gowrishankar MuthukrishnanThis patch series enhances virtio crypto PMD to:
* support RSA
* support packed virtio ring
* support vDPA backend
v6:
- patches rebased.
Gowrishankar Muthukrishnan (6):
crypto/virtio: add asymmetric RSA support crypto/virtio: refactor queue operations crypto/virtio: add packed ring support crypto/virtio: add vDPA backend test/crypto: add asymmetric tests for virtio PMD test/crypto: add tests for virtio user PMD
app/test/test_cryptodev.c | 7 + app/test/test_cryptodev.h | 1 + app/test/test_cryptodev_asym.c | 43 + doc/guides/cryptodevs/features/virtio.ini | 4 + doc/guides/rel_notes/release_25_03.rst | 4 + drivers/crypto/virtio/meson.build | 8 + drivers/crypto/virtio/virtio_crypto_algs.h | 2 +- .../virtio/virtio_crypto_capabilities.h | 19 + drivers/crypto/virtio/virtio_cryptodev.c | 1060 +++++++++++------ drivers/crypto/virtio/virtio_cryptodev.h | 18 +- drivers/crypto/virtio/virtio_cvq.c | 228 ++++ drivers/crypto/virtio/virtio_cvq.h | 33 + drivers/crypto/virtio/virtio_logs.h | 6 +- drivers/crypto/virtio/virtio_pci.h | 38 +- drivers/crypto/virtio/virtio_ring.h | 65 +- drivers/crypto/virtio/virtio_rxtx.c | 725 ++++++++++- drivers/crypto/virtio/virtio_rxtx.h | 13 + drivers/crypto/virtio/virtio_user/vhost.h | 90 ++ .../crypto/virtio/virtio_user/vhost_vdpa.c | 710 +++++++++++ .../virtio/virtio_user/virtio_user_dev.c | 749 ++++++++++++ .../virtio/virtio_user/virtio_user_dev.h | 85 ++ drivers/crypto/virtio/virtio_user_cryptodev.c | 575 +++++++++ drivers/crypto/virtio/virtqueue.c | 229 +++- drivers/crypto/virtio/virtqueue.h | 221 +++- lib/cryptodev/cryptodev_pmd.h | 6 + 25 files changed, 4447 insertions(+), 492 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_cvq.c create mode 100644 drivers/crypto/virtio/virtio_cvq.h create mode 100644 drivers/crypto/virtio/virtio_rxtx.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost_vdpa.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.h create mode 100644 drivers/crypto/virtio/virtio_user_cryptodev.c
Signature · 1 line
2.25.1
PATCH v6 1/6 crypto/virtio: add asymmetric RSA support
Asymmetric RSA operations (SIGN, VERIFY, ENCRYPT and DECRYPT) are supported in virtio PMD.
--- doc/guides/cryptodevs/features/virtio.ini | 4 + doc/guides/rel_notes/release_25_03.rst | 4 + .../virtio/virtio_crypto_capabilities.h | 19 + drivers/crypto/virtio/virtio_cryptodev.c | 347 +++++++++++++++--- drivers/crypto/virtio/virtio_cryptodev.h | 2 + drivers/crypto/virtio/virtio_rxtx.c | 247 +++++++++++-- lib/cryptodev/cryptodev_pmd.h | 6 + 7 files changed, 551 insertions(+), 78 deletions(-)
doc/guides/cryptodevs/features/virtio.ini +4 -0
@@ -4,8 +4,11 @@ ; [Features] Symmetric crypto = Y +Asymmetric crypto = Y Sym operation chaining = Y OOP LB In LB Out = Y +RSA PRIV OP KEY EXP = Y +RSA PRIV OP KEY QT = Y ; ; Supported crypto algorithms of the 'virtio' crypto driver.
@@ -30,6 +33,7 @@ SHA1 HMAC = Y ; Supported Asymmetric algorithms of the 'virtio' crypto driver. ; [Asymmetric] +RSA = Y ; ; Supported Operating systems of the 'virtio' crypto driver.
doc/guides/rel_notes/release_25_03.rst +4 -0
@@ -167,6 +167,10 @@ New Features See the :doc:`../compressdevs/zsda` guide for more details on the new driver. +* **Updated virtio crypto driver.** + + Updated virtio crypto driver to support RSA crypto operations. + Removed Items -------------
drivers/crypto/virtio/virtio_crypto_capabilities.h +19 -0
@@ -48,4 +48,23 @@ }, } \ } +#define VIRTIO_ASYM_CAPABILITIES \ + { /* RSA */ \ + .op = RTE_CRYPTO_OP_TYPE_ASYMMETRIC, \ + {.asym = { \ + .xform_capa = { \ + .xform_type = RTE_CRYPTO_ASYM_XFORM_RSA, \ + .op_types = ((1 << RTE_CRYPTO_ASYM_OP_SIGN) | \ + (1 << RTE_CRYPTO_ASYM_OP_VERIFY) | \ + (1 << RTE_CRYPTO_ASYM_OP_ENCRYPT) | \ + (1 << RTE_CRYPTO_ASYM_OP_DECRYPT)), \ + {.modlen = { \ + .min = 1, \ + .max = 1024, \ + .increment = 1 \ + }, } \ + } \ + }, } \ + } +#endif /* _VIRTIO_CRYPTO_CAPABILITIES_H_ */
drivers/crypto/virtio/virtio_cryptodev.c +302 -45
444 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +2 -0
@@ -20,6 +20,8 @@#define VIRTIO_CRYPTO_MAX_KEY_SIZE 256 +#define VIRTIO_CRYPTO_MAX_CTRL_DATA 2048 +extern uint8_t cryptodev_virtio_driver_id;enum virtio_crypto_cmd_id {
drivers/crypto/virtio/virtio_rxtx.c +214 -33
289 lines not on this page · raw message
lib/cryptodev/cryptodev_pmd.h +6 -0
@@ -715,6 +715,12 @@ struct rte_cryptodev_asym_session {uint8_t sess_private_data[]; }; +/** +* Helper macro to get session private data +*/ +#define CRYPTODEV_GET_ASYM_SESS_PRIV (s) \ + ((void *)(((struct rte_cryptodev_asym_session *)s)->sess_private_data)) + #ifdef __cplusplus }#endif
Signature · 1 line
2.25.1
PATCH v6 2/6 crypto/virtio: refactor queue operations
In reply to Gowrishankar MuthukrishnanMove existing control queue operations into a common place that would be shared with other virtio type of devices.
--- drivers/crypto/virtio/meson.build | 1 + drivers/crypto/virtio/virtio_crypto_algs.h | 2 +- drivers/crypto/virtio/virtio_cryptodev.c | 563 ++++++++------------- drivers/crypto/virtio/virtio_cvq.c | 129 +++++ drivers/crypto/virtio/virtio_cvq.h | 33 ++ drivers/crypto/virtio/virtio_pci.h | 6 +- drivers/crypto/virtio/virtio_ring.h | 12 +- drivers/crypto/virtio/virtio_rxtx.c | 44 +- drivers/crypto/virtio/virtio_rxtx.h | 13 + drivers/crypto/virtio/virtqueue.c | 191 ++++++- drivers/crypto/virtio/virtqueue.h | 89 +++- 11 files changed, 692 insertions(+), 391 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_cvq.c create mode 100644 drivers/crypto/virtio/virtio_cvq.h create mode 100644 drivers/crypto/virtio/virtio_rxtx.h
drivers/crypto/virtio/meson.build +1 -0
@@ -11,6 +11,7 @@ includes += include_directories('../../../lib/vhost') deps += 'bus_pci' sources = files( 'virtio_cryptodev.c', + 'virtio_cvq.c', 'virtio_pci.c', 'virtio_rxtx.c', 'virtqueue.c',
drivers/crypto/virtio/virtio_crypto_algs.h +1 -1
@@ -22,7 +22,7 @@ struct virtio_crypto_session { phys_addr_t phys_addr; } aad; -struct virtio_crypto_op_ctrl_req ctrl; +struct virtio_pmd_ctrl ctrl; };#endif /* _VIRTIO_CRYPTO_ALGS_H_ */
drivers/crypto/virtio/virtio_cryptodev.c +217 -346
768 lines not on this page · raw message
drivers/crypto/virtio/virtio_cvq.c new file +129 -0
129 lines not on this page · raw message
drivers/crypto/virtio/virtio_cvq.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Marvell +*/ + +#ifndef _VIRTIO_CVQ_H_ +#define _VIRTIO_CVQ_H_ + +#include <rte_spinlock.h> +#include <virtio_crypto.h> + +#include "virtio_cryptodev.h" + +struct virtqueue ; + +struct virtcrypto_ctl { +const struct rte_memzone *hdr_mz;/**< memzone to populate hdr. */ +rte_iova_t hdr_mem;/**< hdr for each xmit packet */ +rte_spinlock_t lock;/**< spinlock for control queue. */ +void (*notify_queue)(struct virtqueue *vq,void *cookie);/**< notify ops. */ +void *notify_cookie;/**< cookie for notify ops */ +}; + +struct virtio_pmd_ctrl { +struct virtio_crypto_op_ctrl_req hdr; +struct virtio_crypto_session_input input; +uint8_t data[VIRTIO_CRYPTO_MAX_CTRL_DATA ]; +}; + +int +virtio_crypto_send_command (struct virtcrypto_ctl *cvq,struct virtio_pmd_ctrl *ctrl, +int *dlen,int pkt_num); + +#endif /* _VIRTIO_CVQ_H_ */
drivers/crypto/virtio/virtio_pci.h +4 -2
@@ -176,8 +176,7 @@ struct virtio_pci_ops { };struct virtio_crypto_hw { -/* control queue */ -struct virtqueue *cvq; +struct virtqueue **vqs;uint16_t dev_id;uint16_t max_dataqueues;uint64_t req_guest_features;
@@ -190,6 +189,9 @@ struct virtio_crypto_hw {struct virtio_pci_common_cfg *common_cfg;struct virtio_crypto_config *dev_cfg;const struct rte_cryptodev_capabilities *virtio_dev_capabilities; +uint8_t weak_barriers; +struct virtcrypto_ctl *cvq; +bool use_va; };/*
drivers/crypto/virtio/virtio_ring.h +10 -2
@@ -59,6 +59,7 @@ struct vring_used {struct vring {unsigned int num; +rte_iova_t desc_iova;struct vring_desc *desc;struct vring_avail *avail;struct vring_used *used;
@@ -111,17 +112,24 @@ vring_size(unsigned int num, unsigned long align) }static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p, -unsigned long align) +vring_init_split (struct vring *vr,uint8_t *p,rte_iova_t iova, +unsigned long align,unsigned int num) { vr->num = num; vr->desc = (struct vring_desc *) p; + vr->desc_iova = iova; vr->avail = (struct vring_avail *) (p + num *sizeof (struct vring_desc )); vr->used = (void *)RTE_ALIGN_CEIL ((uintptr_t )(&vr->avail->ring[num]), align); } +static inline void +vring_init (struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) +{ +vring_init_split (vr, p,0 , align, num); +} +/* * The following is used with VIRTIO_RING_F_EVENT_IDX. * Assuming a given event_idx value from the other size, if we have
drivers/crypto/virtio/virtio_rxtx.c +17 -27
119 lines not on this page · raw message
drivers/crypto/virtio/virtio_rxtx.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2025 Marvell. +*/ + +#ifndef _VIRTIO_RXTX_H_ +#define _VIRTIO_RXTX_H_ + +struct virtcrypto_data { +const struct rte_memzone *hdr_mz;/**< memzone to populate hdr. */ +rte_iova_t hdr_mem;/**< hdr for each xmit packet */ +}; + +#endif /* _VIRTIO_RXTX_H_ */
drivers/crypto/virtio/virtqueue.c +188 -3
212 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h +79 -10
162 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v6 3/6 crypto/virtio: add packed ring support
In reply to Gowrishankar MuthukrishnanAdd packed ring support.
--- drivers/crypto/virtio/virtio_cryptodev.c | 125 +++++++ drivers/crypto/virtio/virtio_cryptodev.h | 13 +- drivers/crypto/virtio/virtio_cvq.c | 103 +++++- drivers/crypto/virtio/virtio_pci.h | 25 ++ drivers/crypto/virtio/virtio_ring.h | 59 ++- drivers/crypto/virtio/virtio_rxtx.c | 444 ++++++++++++++++++++++- drivers/crypto/virtio/virtqueue.c | 50 ++- drivers/crypto/virtio/virtqueue.h | 134 ++++++- 8 files changed, 924 insertions(+), 29 deletions(-)
drivers/crypto/virtio/virtio_cryptodev.c +125 -0
@@ -869,6 +869,125 @@ virtio_crypto_clear_session(rte_free (ctrl); } +static void +virtio_crypto_clear_session_packed ( +struct rte_cryptodev *dev, +struct virtio_crypto_op_ctrl_req *ctrl) +{ +struct virtio_crypto_hw *hw; +struct virtqueue *vq; +struct vring_packed_desc *desc; +uint8_t *status; +uint8_t needed =1 ; +uint32_t head; +uint64_t malloc_phys_addr; +uint8_t len_inhdr =sizeof (struct virtio_crypto_inhdr ); +uint32_t len_op_ctrl_req =sizeof (struct virtio_crypto_op_ctrl_req ); +uint64_t session_id = ctrl->u.destroy_session.session_id; +uint16_t flags; +uint8_t nb_descs =0 ; + + hw = dev->data->dev_private; + vq =virtcrypto_cq_to_vq (hw->cvq); + head = vq->vq_avail_idx; + flags = vq->vq_packed.cached_flags; + +VIRTIO_CRYPTO_SESSION_LOG_INFO ("vq->vq_desc_head_idx = %d, " +"vq = %p" , vq->vq_desc_head_idx, vq); + +if (vq->vq_free_cnt < needed) { +VIRTIO_CRYPTO_SESSION_LOG_ERR ( +"vq->vq_free_cnt = %d is less than %d, " +"not enough" , vq->vq_free_cnt, needed); +return ; + } + + malloc_phys_addr =rte_malloc_virt2iova (ctrl); + +/* status part */ + status = &(((struct virtio_crypto_inhdr *) + ((uint8_t *)ctrl + len_op_ctrl_req))->status); + *status =VIRTIO_CRYPTO_ERR ; + +/* indirect desc vring part */ + desc = vq->vq_packed.ring.desc; + +/* ctrl request part */ + desc[head].addr = malloc_phys_addr; + desc[head].len = len_op_ctrl_req; + desc[head].flags =VRING_DESC_F_NEXT | vq->vq_packed.cached_flags; + vq->vq_free_cnt--; + nb_descs++; +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^=VRING_PACKED_DESC_F_AVAIL_USED ; + } + +/* status part */ + desc[vq->vq_avail_idx].addr = malloc_phys_addr + len_op_ctrl_req; + desc[vq->vq_avail_idx].len = len_inhdr; + desc[vq->vq_avail_idx].flags =VRING_DESC_F_WRITE ; + vq->vq_free_cnt--; + nb_descs++; +if (++vq->vq_avail_idx >= vq->vq_nentries) { + vq->vq_avail_idx -= vq->vq_nentries; + vq->vq_packed.cached_flags ^=VRING_PACKED_DESC_F_AVAIL_USED ; + } + +virtqueue_store_flags_packed (&desc[head],VRING_DESC_F_NEXT | flags, + vq->hw->weak_barriers); + +virtio_wmb (vq->hw->weak_barriers); +virtqueue_notify (vq); + +/* wait for used desc in virtqueue +* desc_is_used has a load-acquire or rte_io_rmb inside +*/ +rte_rmb (); +while (!desc_is_used (&desc[head], vq)) { +rte_rmb (); +usleep (100 ); + } + +/* now get used descriptors */ + vq->vq_free_cnt += nb_descs; + vq->vq_used_cons_idx += nb_descs; +if (vq->vq_used_cons_idx >= vq->vq_nentries) { + vq->vq_used_cons_idx -= vq->vq_nentries; + vq->vq_packed.used_wrap_counter ^=1 ; + } + +PMD_INIT_LOG (DEBUG ,"vq->vq_free_cnt=%d " +"vq->vq_queue_idx=%d " +"vq->vq_avail_idx=%d " +"vq->vq_used_cons_idx=%d " +"vq->vq_packed.cached_flags=0x%x " +"vq->vq_packed.used_wrap_counter=%d" , + vq->vq_free_cnt, + vq->vq_queue_index, + vq->vq_avail_idx, + vq->vq_used_cons_idx, + vq->vq_packed.cached_flags, + vq->vq_packed.used_wrap_counter); + +if (*status !=VIRTIO_CRYPTO_OK ) { +VIRTIO_CRYPTO_SESSION_LOG_ERR ("Close session failed " +"status=%" PRIu32", session_id=%" PRIu64"" , + *status, session_id); +rte_free (ctrl); +return ; + } + +VIRTIO_CRYPTO_INIT_LOG_DBG ("vq->vq_free_cnt=%d " +"vq->vq_desc_head_idx=%d" , + vq->vq_free_cnt, vq->vq_desc_head_idx); + +VIRTIO_CRYPTO_SESSION_LOG_INFO ("Close session %" PRIu64" successfully " , + session_id); + +rte_free (ctrl); +} + static void virtio_crypto_sym_clear_session( struct rte_cryptodev *dev,
@@ -906,6 +1025,9 @@ virtio_crypto_sym_clear_session( ctrl->header.queue_id =0 ; ctrl->u.destroy_session.session_id = session->session_id; +if (vtpci_with_packed_queue (dev->data->dev_private)) +return virtio_crypto_clear_session_packed (dev, ctrl); +return virtio_crypto_clear_session (dev, ctrl); }
@@ -943,6 +1065,9 @@ virtio_crypto_asym_clear_session( ctrl->header.queue_id =0 ; ctrl->u.destroy_session.session_id = session->session_id; +if (vtpci_with_packed_queue (dev->data->dev_private)) +return virtio_crypto_clear_session_packed (dev, ctrl); +return virtio_crypto_clear_session (dev, ctrl); }
drivers/crypto/virtio/virtio_cryptodev.h +12 -1
@@ -10,13 +10,21 @@#include "virtio_ring.h" /* Features desired/implemented by this driver. */ -#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1) +#define VIRTIO_CRYPTO_PMD_GUEST_FEATURES (1ULL << VIRTIO_F_VERSION_1 | \ + 1ULL << VIRTIO_F_IN_ORDER | \ + 1ULL << VIRTIO_F_RING_PACKED | \ + 1ULL << VIRTIO_F_NOTIFICATION_DATA | \ + 1ULL << VIRTIO_RING_F_INDIRECT_DESC | \ + 1ULL << VIRTIO_F_ORDER_PLATFORM)#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio#define NUM_ENTRY_VIRTIO_CRYPTO_OP 7#define VIRTIO_CRYPTO_MAX_IV_SIZE 16 +#define VIRTIO_CRYPTO_MAX_MSG_SIZE 512 +#define VIRTIO_CRYPTO_MAX_SIGN_SIZE 512 +#define VIRTIO_CRYPTO_MAX_CIPHER_SIZE 1024#define VIRTIO_CRYPTO_MAX_KEY_SIZE 256
@@ -36,6 +44,9 @@ struct virtio_crypto_op_cookie {struct virtio_crypto_inhdr inhdr;struct vring_desc desc[NUM_ENTRY_VIRTIO_CRYPTO_OP ];uint8_t iv[VIRTIO_CRYPTO_MAX_IV_SIZE ]; +uint8_t message[VIRTIO_CRYPTO_MAX_MSG_SIZE ]; +uint8_t sign[VIRTIO_CRYPTO_MAX_SIGN_SIZE ]; +uint8_t cipher[VIRTIO_CRYPTO_MAX_CIPHER_SIZE ]; };/*
drivers/crypto/virtio/virtio_cvq.c +101 -2
115 lines not on this page · raw message
drivers/crypto/virtio/virtio_pci.h +25 -0
@@ -83,6 +83,25 @@ struct virtqueue;#define VIRTIO_F_VERSION_1 32#define VIRTIO_F_IOMMU_PLATFORM 33 +#define VIRTIO_F_RING_PACKED 34 + +/* +* Inorder feature indicates that all buffers are used by the device +* in the same order in which they have been made available. +*/ +#define VIRTIO_F_IN_ORDER 35 + +/* +* This feature indicates that memory accesses by the driver and the device +* are ordered in a way described by the platform. +*/ +#define VIRTIO_F_ORDER_PLATFORM 36 + +/* +* This feature indicates that the driver passes extra data (besides +* identifying the virtqueue) in its device notifications. +*/ +#define VIRTIO_F_NOTIFICATION_DATA 38/* The Guest publishes the used index for which it expects an interrupt * at the end of the avail ring. Host should ignore the avail->flags field.
@@ -230,6 +249,12 @@ vtpci_with_feature(struct virtio_crypto_hw *hw, uint64_t bit)return (hw->guest_features & (1ULL << bit)) !=0 ; } +static inline int +vtpci_with_packed_queue (struct virtio_crypto_hw *hw) +{ +return vtpci_with_feature (hw,VIRTIO_F_RING_PACKED ); +} +/* * Function declaration from virtio_pci.c */
drivers/crypto/virtio/virtio_ring.h +58 -1
86 lines not on this page · raw message
drivers/crypto/virtio/virtio_rxtx.c +433 -11
496 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.c +42 -8
84 lines not on this page · raw message
drivers/crypto/virtio/virtqueue.h +128 -6
175 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v6 4/6 crypto/virtio: add vDPA backend
In reply to Gowrishankar MuthukrishnanAdd vDPA backend to virtio_user crypto.
--- drivers/crypto/virtio/meson.build | 7 + drivers/crypto/virtio/virtio_cryptodev.c | 57 +- drivers/crypto/virtio/virtio_cryptodev.h | 3 + drivers/crypto/virtio/virtio_logs.h | 6 +- drivers/crypto/virtio/virtio_pci.h | 7 + drivers/crypto/virtio/virtio_ring.h | 6 - drivers/crypto/virtio/virtio_user/vhost.h | 90 +++ .../crypto/virtio/virtio_user/vhost_vdpa.c | 710 +++++++++++++++++ .../virtio/virtio_user/virtio_user_dev.c | 749 ++++++++++++++++++ .../virtio/virtio_user/virtio_user_dev.h | 85 ++ drivers/crypto/virtio/virtio_user_cryptodev.c | 575 ++++++++++++++ 11 files changed, 2265 insertions(+), 30 deletions(-) create mode 100644 drivers/crypto/virtio/virtio_user/vhost.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost_vdpa.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.h create mode 100644 drivers/crypto/virtio/virtio_user_cryptodev.c
drivers/crypto/virtio/meson.build +7 -0
@@ -16,3 +16,10 @@ sources = files( 'virtio_rxtx.c', 'virtqueue.c', ) + +if is_linux + sources += files('virtio_user_cryptodev.c', + 'virtio_user/vhost_vdpa.c', + 'virtio_user/virtio_user_dev.c') + deps += ['bus_vdev'] +endif
drivers/crypto/virtio/virtio_cryptodev.c +35 -22
75 lines not on this page · raw message
drivers/crypto/virtio/virtio_cryptodev.h +3 -0
@@ -76,4 +76,7 @@ uint16_t virtio_crypto_pkt_rx_burst(void *tx_queue,struct rte_crypto_op **tx_pkts, uint16_t nb_pkts); +int crypto_virtio_dev_init (struct rte_cryptodev *cryptodev,uint64_t features, +struct rte_pci_device *pci_dev); +#endif /* _VIRTIO_CRYPTODEV_H_ */
drivers/crypto/virtio/virtio_logs.h +4 -2
@@ -15,8 +15,10 @@ extern int virtio_crypto_logtype_init;#define PMD_INIT_FUNC_TRACE () PMD_INIT_LOG(DEBUG, " >>") -extern int virtio_crypto_logtype_init; -#define RTE_LOGTYPE_VIRTIO_CRYPTO_INIT virtio_crypto_logtype_init +extern int virtio_crypto_logtype_driver; +#define RTE_LOGTYPE_VIRTIO_CRYPTO_DRIVER virtio_crypto_logtype_driver +#define PMD_DRV_LOG (level, ...) \ + RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_DRIVER, "%s(): ", __func__, __VA_ARGS__)#define VIRTIO_CRYPTO_INIT_LOG_IMPL (level, ...) \ RTE_LOG_LINE_PREFIX(level, VIRTIO_CRYPTO_INIT, "%s(): ", __func__, __VA_ARGS__)
drivers/crypto/virtio/virtio_pci.h +7 -0
@@ -20,6 +20,9 @@ struct virtqueue;#define VIRTIO_CRYPTO_PCI_VENDORID 0x1AF4#define VIRTIO_CRYPTO_PCI_DEVICEID 0x1054 +/* VirtIO device IDs. */ +#define VIRTIO_ID_CRYPTO 20 +/* VirtIO ABI version, this must match exactly. */ #define VIRTIO_PCI_ABI_VERSION 0
@@ -56,8 +59,12 @@ struct virtqueue;#define VIRTIO_CONFIG_STATUS_DRIVER 0x02#define VIRTIO_CONFIG_STATUS_DRIVER_OK 0x04#define VIRTIO_CONFIG_STATUS_FEATURES_OK 0x08 +#define VIRTIO_CONFIG_STATUS_DEV_NEED_RESET 0x40#define VIRTIO_CONFIG_STATUS_FAILED 0x80 +/* The alignment to use between consumer and producer parts of vring. */ +#define VIRTIO_VRING_ALIGN 4096 +/* * Each virtqueue indirect descriptor list must be physically contiguous. * To allow us to malloc(9) each list individually, limit the number
drivers/crypto/virtio/virtio_ring.h +0 -6
@@ -181,12 +181,6 @@ vring_init_packed(struct vring_packed *vr, uint8_t *p, rte_iova_t iova, sizeof(struct vring_packed_desc_event)), align); } -static inline void -vring_init (struct vring *vr,unsigned int num,uint8_t *p,unsigned long align) -{ -vring_init_split (vr, p,0 , align, num); -} -/* * The following is used with VIRTIO_RING_F_EVENT_IDX. * Assuming a given event_idx value from the other size, if we have
drivers/crypto/virtio/virtio_user/vhost.h new file +90 -0
90 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/vhost_vdpa.c new file +710 -0
710 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/virtio_user_dev.c new file +749 -0
749 lines not on this page · raw message
drivers/crypto/virtio/virtio_user/virtio_user_dev.h new file +85 -0
85 lines not on this page · raw message
drivers/crypto/virtio/virtio_user_cryptodev.c new file +575 -0
575 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v6 5/6 test/crypto: add asymmetric tests for virtio PMD
In reply to Gowrishankar MuthukrishnanAdd asymmetric tests for Virtio PMD.
--- app/test/test_cryptodev_asym.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
app/test/test_cryptodev_asym.c +28 -0
@@ -4023,6 +4023,19 @@ static struct unit_test_suite cryptodev_octeontx_asym_testsuite = { } }; +static struct unit_test_suite cryptodev_virtio_asym_testsuite = { + .suite_name ="Crypto Device VIRTIO ASYM Unit Test Suite" , + .setup = testsuite_setup, + .teardown = testsuite_teardown, + .unit_test_cases = { +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, test_capability), +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, + test_rsa_sign_verify_crt), +TEST_CASE_ST (ut_setup_asym, ut_teardown_asym, test_rsa_enc_dec_crt), +TEST_CASES_END ()/**< NULL terminate unit test array */ + } +}; +static int test_cryptodev_openssl_asym (void ) {
@@ -4091,8 +4104,23 @@ test_cryptodev_cn10k_asym(void)return unit_test_suite_runner (&cryptodev_octeontx_asym_testsuite); } +static int +test_cryptodev_virtio_asym (void ) +{ + gbl_driver_id =rte_cryptodev_driver_id_get ( +RTE_STR (CRYPTODEV_NAME_VIRTIO_PMD )); +if (gbl_driver_id ==-1 ) { +RTE_LOG (ERR ,USER1 ,"virtio PMD must be loaded.\n" ); +return TEST_FAILED ; + } + +/* Use test suite registered for crypto_virtio PMD */ +return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); +} +REGISTER_DRIVER_TEST (cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);REGISTER_DRIVER_TEST (cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);REGISTER_DRIVER_TEST (cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);REGISTER_DRIVER_TEST (cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);REGISTER_DRIVER_TEST (cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym); +REGISTER_DRIVER_TEST (cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym);
Signature · 1 line
2.25.1
PATCH v6 6/6 test/crypto: add tests for virtio user PMD
In reply to Gowrishankar MuthukrishnanReuse virtio_crypto tests for testing virtio_crypto_user PMD.
--- app/test/test_cryptodev.c | 7 +++++++ app/test/test_cryptodev.h | 1 + app/test/test_cryptodev_asym.c | 15 +++++++++++++++ 3 files changed, 23 insertions(+)
app/test/test_cryptodev.c +7 -0
@@ -19737,6 +19737,12 @@ test_cryptodev_virtio(void)return run_cryptodev_testsuite (RTE_STR (CRYPTODEV_NAME_VIRTIO_PMD )); } +static int +test_cryptodev_virtio_user (void ) +{ +return run_cryptodev_testsuite (RTE_STR (CRYPTODEV_NAME_VIRTIO_USER_PMD )); +} +static int test_cryptodev_aesni_mb (void ) {
@@ -20074,6 +20080,7 @@ REGISTER_DRIVER_TEST(cryptodev_dpaa_sec_autotest, test_cryptodev_dpaa_sec);REGISTER_DRIVER_TEST (cryptodev_ccp_autotest, test_cryptodev_ccp);REGISTER_DRIVER_TEST (cryptodev_uadk_autotest, test_cryptodev_uadk);REGISTER_DRIVER_TEST (cryptodev_virtio_autotest, test_cryptodev_virtio); +REGISTER_DRIVER_TEST (cryptodev_virtio_user_autotest, test_cryptodev_virtio_user);REGISTER_DRIVER_TEST (cryptodev_octeontx_autotest, test_cryptodev_octeontx);REGISTER_DRIVER_TEST (cryptodev_caam_jr_autotest, test_cryptodev_caam_jr);REGISTER_DRIVER_TEST (cryptodev_nitrox_autotest, test_cryptodev_nitrox);
app/test/test_cryptodev.h +1 -0
@@ -64,6 +64,7 @@#define CRYPTODEV_NAME_MVSAM_PMD crypto_mvsam#define CRYPTODEV_NAME_CCP_PMD crypto_ccp#define CRYPTODEV_NAME_VIRTIO_PMD crypto_virtio +#define CRYPTODEV_NAME_VIRTIO_USER_PMD crypto_virtio_user#define CRYPTODEV_NAME_OCTEONTX_SYM_PMD crypto_octeontx#define CRYPTODEV_NAME_CAAM_JR_PMD crypto_caam_jr#define CRYPTODEV_NAME_NITROX_PMD crypto_nitrox_sym
app/test/test_cryptodev_asym.c +15 -0
@@ -4118,9 +4118,24 @@ test_cryptodev_virtio_asym(void)return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); } +static int +test_cryptodev_virtio_user_asym (void ) +{ + gbl_driver_id =rte_cryptodev_driver_id_get ( +RTE_STR (CRYPTODEV_NAME_VIRTIO_USER_PMD )); +if (gbl_driver_id ==-1 ) { +RTE_LOG (ERR ,USER1 ,"virtio user PMD must be loaded.\n" ); +return TEST_FAILED ; + } + +/* Use test suite registered for crypto_virtio_user PMD */ +return unit_test_suite_runner (&cryptodev_virtio_asym_testsuite); +} +REGISTER_DRIVER_TEST (cryptodev_openssl_asym_autotest, test_cryptodev_openssl_asym);REGISTER_DRIVER_TEST (cryptodev_qat_asym_autotest, test_cryptodev_qat_asym);REGISTER_DRIVER_TEST (cryptodev_octeontx_asym_autotest, test_cryptodev_octeontx_asym);REGISTER_DRIVER_TEST (cryptodev_cn9k_asym_autotest, test_cryptodev_cn9k_asym);REGISTER_DRIVER_TEST (cryptodev_cn10k_asym_autotest, test_cryptodev_cn10k_asym);REGISTER_DRIVER_TEST (cryptodev_virtio_asym_autotest, test_cryptodev_virtio_asym); +REGISTER_DRIVER_TEST (cryptodev_virtio_user_asym_autotest, test_cryptodev_virtio_user_asym);
Signature · 1 line
2.25.1
Akhil Goyal
AppliedRE: [v6 0/6] crypto/virtio: enhancements for RSA and vDPA
In reply to Gowrishankar MuthukrishnanQuoted 44 lines
Subject: [v6 0/6]
crypto/virtio: enhancements for RSA and vDPAThis patch series enhances virtio crypto PMD to:
* support RSA
* support packed virtio ring
* support vDPA backendv6:
- patches rebased.Gowrishankar Muthukrishnan (6):
crypto/virtio: add asymmetric RSA supportcrypto/virtio: refactor queue operationscrypto/virtio: add packed ring supportcrypto/virtio: add vDPA backend test/crypto: add asymmetric tests for virtio PMD test/crypto: add tests for virtio user PMDapp/test/test_cryptodev.c | 7 + app/test/test_cryptodev.h | 1 + app/test/test_cryptodev_asym.c | 43 + doc/guides/cryptodevs/features/virtio.ini | 4 + doc/guides/rel_notes/release_25_03.rst | 4 + drivers/crypto/virtio/meson.build | 8 + drivers/crypto/virtio/virtio_crypto_algs.h | 2 +- .../virtio/virtio_crypto_capabilities.h | 19 + drivers/crypto/virtio/virtio_cryptodev.c | 1060 +++++++++++------ drivers/crypto/virtio/virtio_cryptodev.h | 18 +- drivers/crypto/virtio/virtio_cvq.c | 228 ++++ drivers/crypto/virtio/virtio_cvq.h | 33 + drivers/crypto/virtio/virtio_logs.h | 6 +- drivers/crypto/virtio/virtio_pci.h | 38 +- drivers/crypto/virtio/virtio_ring.h | 65 +- drivers/crypto/virtio/virtio_rxtx.c | 725 ++++++++++- drivers/crypto/virtio/virtio_rxtx.h | 13 + drivers/crypto/virtio/virtio_user/vhost.h | 90 ++ .../crypto/virtio/virtio_user/vhost_vdpa.c | 710 +++++++++++ .../virtio/virtio_user/virtio_user_dev.c | 749 ++++++++++++ .../virtio/virtio_user/virtio_user_dev.h | 85 ++ drivers/crypto/virtio/virtio_user_cryptodev.c | 575 +++++++++ drivers/crypto/virtio/virtqueue.c | 229 +++- drivers/crypto/virtio/virtqueue.h | 221 +++- lib/cryptodev/cryptodev_pmd.h | 6 + 25 files changed, 4447 insertions(+), 492 deletions(-)
Quoted 8 lines
create mode 100644 drivers/crypto/virtio/virtio_cvq.c create mode 100644 drivers/crypto/virtio/virtio_cvq.h create mode 100644 drivers/crypto/virtio/virtio_rxtx.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost.h create mode 100644 drivers/crypto/virtio/virtio_user/vhost_vdpa.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.c create mode 100644 drivers/crypto/virtio/virtio_user/virtio_user_dev.h create mode 100644 drivers/crypto/virtio/virtio_user_cryptodev.c
Series Acked-by: Akhil Goyal <[email protected]>
Applied to dpdk-next-crypto
Thanks.
v2 cover vhost: add RSA support
In reply to Gowrishankar MuthukrishnanThis series adds RSA support in vhost_crypto library.
v2:
- split from v1 series.
Depends-on: series-34291 ("crypto/virtio: add RSA support")
Gowrishankar Muthukrishnan (2):
vhost: add asymmetric RSA support
examples/vhost_crypto: add asymmetric support
examples/vhost_crypto/main.c | 54 +++- lib/vhost/vhost_crypto.c | 504 ++++++++++++++++++++++++++++++++--- lib/vhost/vhost_user.h | 33 ++- 3 files changed, 538 insertions(+), 53 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 vhost: add asymmetric RSA support
Support asymmetric RSA crypto operations in vhost-user.
---
Depends-on: series-34291 ("crypto/virtio: add RSA support")
lib/vhost/vhost_crypto.c | 504 ++++++++++++++++++++++++++++++++++++--- lib/vhost/vhost_user.h | 33 ++- 2 files changed, 498 insertions(+), 39 deletions(-)
lib/vhost/vhost_crypto.c +469 -35
@@ -54,6 +54,14 @@ RTE_LOG_REGISTER_SUFFIX(vhost_crypto_logtype, crypto, INFO);*/ #define vhost_crypto_desc vring_desc +struct vhost_crypto_session { +union { +struct rte_cryptodev_asym_session *asym; +struct rte_cryptodev_sym_session *sym; + }; +enum rte_crypto_op_type type; +}; +static int cipher_algo_transform (uint32_t virtio_cipher_algo,enum rte_crypto_cipher_algorithm *algo)
@@ -206,8 +214,10 @@ struct __rte_cache_aligned vhost_crypto {uint64_t last_session_id; -uint64_t cache_session_id; -struct rte_cryptodev_sym_session *cache_session; +uint64_t cache_sym_session_id; +struct rte_cryptodev_sym_session *cache_sym_session; +uint64_t cache_asym_session_id; +struct rte_cryptodev_asym_session *cache_asym_session;/** socket id for the device */ int socket_id;
@@ -237,7 +247,7 @@ struct vhost_crypto_data_req {static int transform_cipher_param (struct rte_crypto_sym_xform *xform, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {int ret;
@@ -273,7 +283,7 @@ transform_cipher_param(struct rte_crypto_sym_xform *xform,static int transform_chain_param (struct rte_crypto_sym_xform *xforms, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {struct rte_crypto_sym_xform *xform_cipher, *xform_auth;int ret;
@@ -334,17 +344,17 @@ transform_chain_param(struct rte_crypto_sym_xform *xforms, }static void -vhost_crypto_create_sess (struct vhost_crypto *vcrypto, +vhost_crypto_create_sym_sess (struct vhost_crypto *vcrypto,VhostUserCryptoSessionParam *sess_param) {struct rte_crypto_sym_xform xform1 = {0 }, xform2 = {0 };struct rte_cryptodev_sym_session *session;int ret; -switch (sess_param->op_type) { +switch (sess_param->u.sym_sess.op_type) {case VIRTIO_CRYPTO_SYM_OP_NONE :case VIRTIO_CRYPTO_SYM_OP_CIPHER : - ret =transform_cipher_param (&xform1, sess_param); + ret =transform_cipher_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session msg (%i)" , ret); sess_param->session_id = ret;
@@ -352,7 +362,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, }break ;case VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING : -if (unlikely (sess_param->hash_mode != +if (unlikely (sess_param->u.sym_sess.hash_mode !=VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH )) { sess_param->session_id = -VIRTIO_CRYPTO_NOTSUPP ; VC_LOG_ERR("Error transform session message (%i)",
@@ -362,7 +372,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, xform1.next = &xform2; - ret =transform_chain_param (&xform1, sess_param); + ret =transform_chain_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session message (%i)" , ret); sess_param->session_id = ret;
@@ -402,22 +412,264 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, vcrypto->last_session_id++; } +static int +tlv_decode (uint8_t *tlv,uint8_t type,uint8_t **data,size_t *data_len) +{ +size_t tlen = -EINVAL , len; + +if (tlv[0 ] != type) +return -EINVAL ; + +if (tlv[1 ] ==0x82 ) { + len = (tlv[2 ] <<8 ) | tlv[3 ]; + *data =rte_malloc (NULL , len,0 ); +rte_memcpy (*data, &tlv[4 ], len); + tlen = len +4 ; + }else if (tlv[1 ] ==0x81 ) { + len = tlv[2 ]; + *data =rte_malloc (NULL , len,0 ); +rte_memcpy (*data, &tlv[3 ], len); + tlen = len +3 ; + }else { + len = tlv[1 ]; + *data =rte_malloc (NULL , len,0 ); +rte_memcpy (*data, &tlv[2 ], len); + tlen = len +2 ; + } + + *data_len = len; +return tlen; +} + +static int +virtio_crypto_asym_rsa_der_to_xform (uint8_t *der,size_t der_len, +struct rte_crypto_asym_xform *xform) +{ +uint8_t *n =NULL , *e =NULL , *d =NULL , *p =NULL , *q =NULL , *dp =NULL , + *dq =NULL , *qinv =NULL , *v =NULL , *tlv; +size_t nlen, elen, dlen, plen, qlen, dplen, dqlen, qinvlen, vlen; +int len; + +RTE_SET_USED (der_len); + +if (der[0 ] !=0x30 ) +return -EINVAL ; + +if (der[1 ] ==0x82 ) + tlv = &der[4 ]; +else if (der[1 ] ==0x81 ) + tlv = &der[3 ]; +else +return -EINVAL ; + + len =tlv_decode (tlv,0x02 , &v, &vlen); +if (len <0 || v[0 ] !=0x0 || vlen !=1 ) { + len = -EINVAL ; + goto _error; + } + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &n, &nlen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &e, &elen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &d, &dlen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &p, &plen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &q, &qlen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &dp, &dplen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &dq, &dqlen); +if (len <0 ) + goto _error; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &qinv, &qinvlen); +if (len <0 ) + goto _error; + + xform->rsa.n.data = n; + xform->rsa.n.length = nlen; + xform->rsa.e.data = e; + xform->rsa.e.length = elen; + xform->rsa.d.data = d; + xform->rsa.d.length = dlen; + xform->rsa.qt.p.data = p; + xform->rsa.qt.p.length = plen; + xform->rsa.qt.q.data = q; + xform->rsa.qt.q.length = qlen; + xform->rsa.qt.dP.data = dp; + xform->rsa.qt.dP.length = dplen; + xform->rsa.qt.dQ.data = dq; + xform->rsa.qt.dQ.length = dqlen; + xform->rsa.qt.qInv.data = qinv; + xform->rsa.qt.qInv.length = qinvlen; + +RTE_ASSERT ((tlv + len - &der[0 ]) == der_len); +return 0 ; +_error: +rte_free (v); +rte_free (n); +rte_free (e); +rte_free (d); +rte_free (p); +rte_free (q); +rte_free (dp); +rte_free (dq); +rte_free (qinv); +return len; +} + +static int +transform_rsa_param (struct rte_crypto_asym_xform *xform, +VhostUserCryptoAsymSessionParam *param) +{ +int ret = -EINVAL ; + + ret =virtio_crypto_asym_rsa_der_to_xform (param->key_buf, param->key_len, xform); +if (ret <0 ) + goto _error; + +switch (param->u.rsa.padding_algo) { +case VIRTIO_CRYPTO_RSA_RAW_PADDING : + xform->rsa.padding.type =RTE_CRYPTO_RSA_PADDING_NONE ; +break ; +case VIRTIO_CRYPTO_RSA_PKCS1_PADDING : + xform->rsa.padding.type =RTE_CRYPTO_RSA_PADDING_PKCS1_5 ; +break ; +default : +VC_LOG_ERR ("Unknown padding type" ); + goto _error; + } + + xform->rsa.key_type =RTE_RSA_KEY_TYPE_QT ; + xform->xform_type =RTE_CRYPTO_ASYM_XFORM_RSA ; +_error: +return ret; +} + +static void +vhost_crypto_create_asym_sess (struct vhost_crypto *vcrypto, +VhostUserCryptoSessionParam *sess_param) +{ +struct rte_cryptodev_asym_session *session =NULL ; +struct vhost_crypto_session *vhost_session; +struct rte_crypto_asym_xform xform = {0 }; +int ret; + +switch (sess_param->u.asym_sess.algo) { +case VIRTIO_CRYPTO_AKCIPHER_RSA : + ret =transform_rsa_param (&xform, &sess_param->u.asym_sess); +if (unlikely (ret)) { +VC_LOG_ERR ("Error transform session msg (%i)" , ret); + sess_param->session_id = ret; +return ; + } +break ; +default : +VC_LOG_ERR ("Invalid op algo" ); + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +return ; + } + + ret =rte_cryptodev_asym_session_create (vcrypto->cid, &xform, + vcrypto->sess_pool, (void *)&session); +if (!session) { +VC_LOG_ERR ("Failed to create session" ); + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +return ; + } + +/* insert session to map */ + vhost_session =rte_malloc (NULL ,sizeof (*vhost_session),0 ); +if (vhost_session ==NULL ) { +VC_LOG_ERR ("Failed to alloc session memory" ); + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +return ; + } + + vhost_session->type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + vhost_session->asym = session; +if ((rte_hash_add_key_data (vcrypto->session_map, + &vcrypto->last_session_id, vhost_session) <0 )) { +VC_LOG_ERR ("Failed to insert session to hash table" ); + +if (rte_cryptodev_asym_session_free (vcrypto->cid, session) <0 ) +VC_LOG_ERR ("Failed to free session" ); + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +return ; + } + +VC_LOG_INFO ("Session %" PRIu64" created for vdev %i." , + vcrypto->last_session_id, vcrypto->dev->vid); + + sess_param->session_id = vcrypto->last_session_id; + vcrypto->last_session_id++; +} + +static void +vhost_crypto_create_sess (struct vhost_crypto *vcrypto, +VhostUserCryptoSessionParam *sess_param) +{ +if (sess_param->op_code ==VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION ) +vhost_crypto_create_asym_sess (vcrypto, sess_param); +else +vhost_crypto_create_sym_sess (vcrypto, sess_param); +} +static int vhost_crypto_close_sess (struct vhost_crypto *vcrypto,uint64_t session_id) { -struct rte_cryptodev_sym_session *session; +struct rte_cryptodev_asym_session *asym_session =NULL ; +struct rte_cryptodev_sym_session *sym_session =NULL ; +struct vhost_crypto_session *vhost_session =NULL ;uint64_t sess_id = session_id;int ret; ret =rte_hash_lookup_data (vcrypto->session_map, &sess_id, - (void **)&session); - + (void **)&vhost_session);if (unlikely (ret <0 )) { -VC_LOG_ERR ("Failed to delete session %" PRIu64"." , session_id); +VC_LOG_ERR ("Failed to find session for id %" PRIu64"." , session_id); +return -VIRTIO_CRYPTO_INVSESS ; + } + +if (vhost_session->type ==RTE_CRYPTO_OP_TYPE_SYMMETRIC ) { + sym_session = vhost_session->sym; + }else if (vhost_session->type ==RTE_CRYPTO_OP_TYPE_ASYMMETRIC ) { + asym_session = vhost_session->asym; + }else { +VC_LOG_ERR ("Invalid session for id %" PRIu64"." , session_id);return -VIRTIO_CRYPTO_INVSESS ; } -if (rte_cryptodev_sym_session_free (vcrypto->cid, session) <0 ) { +if (sym_session !=NULL && +rte_cryptodev_sym_session_free (vcrypto->cid, sym_session) <0 ) { +VC_LOG_DBG ("Failed to free session" ); +return -VIRTIO_CRYPTO_ERR ; + } + +if (asym_session !=NULL && +rte_cryptodev_asym_session_free (vcrypto->cid, asym_session) <0 ) {VC_LOG_DBG ("Failed to free session" );return -VIRTIO_CRYPTO_ERR ; }
@@ -430,6 +682,7 @@ vhost_crypto_close_sess(struct vhost_crypto *vcrypto, uint64_t session_id)VC_LOG_INFO ("Session %" PRIu64" deleted for vdev %i." , sess_id, vcrypto->dev->vid); +rte_free (vhost_session);return 0 ; }
@@ -1123,6 +1376,118 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,return ret; } +static __rte_always_inline uint8_t +vhost_crypto_check_akcipher_request (struct virtio_crypto_akcipher_data_req *req) +{ +RTE_SET_USED (req); +return VIRTIO_CRYPTO_OK ; +} + +static __rte_always_inline uint8_t +prepare_asym_rsa_op (struct vhost_crypto *vcrypto,struct rte_crypto_op *op, +struct vhost_crypto_data_req *vc_req, +struct virtio_crypto_op_data_req *req, +struct vhost_crypto_desc *head, +uint32_t max_n_descs) +{ +uint8_t ret =vhost_crypto_check_akcipher_request (&req->u.akcipher_req); +struct rte_crypto_rsa_op_param *rsa = &op->asym->rsa; +struct vhost_crypto_desc *desc = head; +uint16_t wlen =0 ; + +if (unlikely (ret !=VIRTIO_CRYPTO_OK )) + goto error_exit; + +/* prepare */ +switch (vcrypto->option) { +case RTE_VHOST_CRYPTO_ZERO_COPY_DISABLE : + vc_req->wb_pool = vcrypto->wb_pool; +if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_SIGN ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_SIGN ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.src_data_len; + rsa->sign.length = req->u.akcipher_req.para.dst_data_len; + wlen = rsa->sign.length; + desc =find_write_desc (head, desc, max_n_descs); +if (unlikely (!desc)) { +VC_LOG_ERR ("Cannot find write location" ); + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + rsa->sign.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RW ); +if (unlikely (rsa->sign.data ==NULL )) { + ret =VIRTIO_CRYPTO_ERR ; + goto error_exit; + } + + desc +=1 ; + }else if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_VERIFY ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_VERIFY ; + rsa->sign.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->sign.length = req->u.akcipher_req.para.src_data_len; + desc +=1 ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.dst_data_len; + desc +=1 ; + }else if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_ENCRYPT ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_ENCRYPT ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.src_data_len; + rsa->cipher.length = req->u.akcipher_req.para.dst_data_len; + wlen = rsa->cipher.length; + desc =find_write_desc (head, desc, max_n_descs); +if (unlikely (!desc)) { +VC_LOG_ERR ("Cannot find write location" ); + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + rsa->cipher.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RW ); +if (unlikely (rsa->cipher.data ==NULL )) { + ret =VIRTIO_CRYPTO_ERR ; + goto error_exit; + } + + desc +=1 ; + }else if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_DECRYPT ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_DECRYPT ; + rsa->cipher.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->cipher.length = req->u.akcipher_req.para.src_data_len; + desc +=1 ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.dst_data_len; + desc +=1 ; + }else { + goto error_exit; + } +break ; +case RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE : +default : + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + op->type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + op->sess_type =RTE_CRYPTO_OP_WITH_SESSION ; + + vc_req->inhdr =get_data_ptr (vc_req, desc,VHOST_ACCESS_WO ); +if (unlikely (vc_req->inhdr ==NULL )) { + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + vc_req->inhdr->status =VIRTIO_CRYPTO_OK ; + vc_req->len = wlen +INHDR_LEN ; +return 0 ; +error_exit: +if (vc_req->wb) +free_wb_data (vc_req->wb, vc_req->wb_pool); + + vc_req->len =INHDR_LEN ; +return ret; +} +/** * Process on descriptor */
@@ -1133,17 +1498,21 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, uint16_t desc_idx) __rte_no_thread_safety_analysis/* FIXME: requires iotlb_lock? */ { -struct vhost_crypto_data_req *vc_req =rte_mbuf_to_priv (op->sym->m_src); -struct rte_cryptodev_sym_session *session; +struct vhost_crypto_data_req *vc_req, *vc_req_out; +struct rte_cryptodev_asym_session *asym_session; +struct rte_cryptodev_sym_session *sym_session; +struct vhost_crypto_session *vhost_session; +struct vhost_crypto_desc *desc = descs; +uint32_t nb_descs =0 , max_n_descs, i; +struct vhost_crypto_data_req data_req;struct virtio_crypto_op_data_req req;struct virtio_crypto_inhdr *inhdr; -struct vhost_crypto_desc *desc = descs;struct vring_desc *src_desc;uint64_t session_id;uint64_t dlen; -uint32_t nb_descs =0 , max_n_descs, i;int err; + vc_req = &data_req; vc_req->desc_idx = desc_idx; vc_req->dev = vcrypto->dev; vc_req->vq = vq;
@@ -1226,12 +1595,14 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto,switch (req.header.opcode) {case VIRTIO_CRYPTO_CIPHER_ENCRYPT :case VIRTIO_CRYPTO_CIPHER_DECRYPT : + vc_req_out =rte_mbuf_to_priv (op->sym->m_src); +rte_memcpy (vc_req_out, vc_req,sizeof (struct vhost_crypto_data_req )); session_id = req.header.session_id;/* one branch to avoid unnecessary table lookup */ -if (vcrypto->cache_session_id != session_id) { +if (vcrypto->cache_sym_session_id != session_id) { err =rte_hash_lookup_data (vcrypto->session_map, - &session_id, (void **)&session); + &session_id, (void **)&vhost_session);if (unlikely (err <0 )) { err =VIRTIO_CRYPTO_ERR ; VC_LOG_ERR("Failed to find session %"PRIu64,
@@ -1239,13 +1610,14 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, goto error_exit; } - vcrypto->cache_session = session; - vcrypto->cache_session_id = session_id; + vcrypto->cache_sym_session = vhost_session->sym; + vcrypto->cache_sym_session_id = session_id; } - session = vcrypto->cache_session; + sym_session = vcrypto->cache_sym_session; + op->type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; - err =rte_crypto_op_attach_sym_session (op, session); + err =rte_crypto_op_attach_sym_session (op, sym_session);if (unlikely (err <0 )) { err =VIRTIO_CRYPTO_ERR ;VC_LOG_ERR ("Failed to attach session to op" );
@@ -1257,12 +1629,12 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, err =VIRTIO_CRYPTO_NOTSUPP ;break ;case VIRTIO_CRYPTO_SYM_OP_CIPHER : - err =prepare_sym_cipher_op (vcrypto, op, vc_req, + err =prepare_sym_cipher_op (vcrypto, op, vc_req_out, &req.u.sym_req.u.cipher, desc, max_n_descs);break ;case VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING : - err =prepare_sym_chain_op (vcrypto, op, vc_req, + err =prepare_sym_chain_op (vcrypto, op, vc_req_out, &req.u.sym_req.u.chain, desc, max_n_descs);break ;
@@ -1271,6 +1643,53 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto,VC_LOG_ERR ("Failed to process sym request" ); goto error_exit; } +break ; +case VIRTIO_CRYPTO_AKCIPHER_SIGN : +case VIRTIO_CRYPTO_AKCIPHER_VERIFY : +case VIRTIO_CRYPTO_AKCIPHER_ENCRYPT : +case VIRTIO_CRYPTO_AKCIPHER_DECRYPT : + session_id = req.header.session_id; + +/* one branch to avoid unnecessary table lookup */ +if (vcrypto->cache_asym_session_id != session_id) { + err =rte_hash_lookup_data (vcrypto->session_map, + &session_id, (void **)&vhost_session); +if (unlikely (err <0 )) { + err =VIRTIO_CRYPTO_ERR ; +VC_LOG_ERR ("Failed to find asym session %" PRIu64, + session_id); + goto error_exit; + } + + vcrypto->cache_asym_session = vhost_session->asym; + vcrypto->cache_asym_session_id = session_id; + } + + asym_session = vcrypto->cache_asym_session; + op->type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + + err =rte_crypto_op_attach_asym_session (op, asym_session); +if (unlikely (err <0 )) { + err =VIRTIO_CRYPTO_ERR ; +VC_LOG_ERR ("Failed to attach asym session to op" ); + goto error_exit; + } + + vc_req_out =rte_cryptodev_asym_session_get_user_data (asym_session); +rte_memcpy (vc_req_out, vc_req,sizeof (struct vhost_crypto_data_req )); + vc_req_out->wb =NULL ; + +switch (req.header.algo) { +case VIRTIO_CRYPTO_AKCIPHER_RSA : + err =prepare_asym_rsa_op (vcrypto, op, vc_req_out, + &req, desc, max_n_descs); +break ; + } +if (unlikely (err !=0 )) { +VC_LOG_ERR ("Failed to process asym request" ); + goto error_exit; + } +break ;default : err =VIRTIO_CRYPTO_ERR ;
@@ -1294,12 +1713,22 @@ static __rte_always_inline struct vhost_virtqueue * vhost_crypto_finalize_one_request(struct rte_crypto_op *op, struct vhost_virtqueue *old_vq) { - struct rte_mbuf *m_src = op->sym->m_src; -struct rte_mbuf *m_dst = op->sym->m_dst; -struct vhost_crypto_data_req *vc_req =rte_mbuf_to_priv (m_src); + struct rte_mbuf *m_src = NULL, *m_dst = NULL; +struct vhost_crypto_data_req *vc_req;struct vhost_virtqueue *vq;uint16_t used_idx, desc_idx; +if (op->type ==RTE_CRYPTO_OP_TYPE_SYMMETRIC ) { + m_src = op->sym->m_src; + m_dst = op->sym->m_dst; + vc_req =rte_mbuf_to_priv (m_src); + }else if (op->type ==RTE_CRYPTO_OP_TYPE_ASYMMETRIC ) { + vc_req =rte_cryptodev_asym_session_get_user_data (op->asym->session); + }else { +VC_LOG_ERR ("Invalid crypto op type" ); +return NULL ; + } +if (unlikely (!vc_req)) {VC_LOG_ERR ("Failed to retrieve vc_req" );return NULL ;
@@ -1321,10 +1750,11 @@ vhost_crypto_finalize_one_request(struct rte_crypto_op *op, vq->used->ring[desc_idx].id = vq->avail->ring[desc_idx]; vq->used->ring[desc_idx].len = vc_req->len; -rte_mempool_put (m_src->pool, (void *)m_src); - -if (m_dst) -rte_mempool_put (m_dst->pool, (void *)m_dst); +if (op->type ==RTE_CRYPTO_OP_TYPE_SYMMETRIC ) { +rte_mempool_put (m_src->pool, (void *)m_src); +if (m_dst) +rte_mempool_put (m_dst->pool, (void *)m_dst); + }return vc_req->vq; }
@@ -1407,8 +1837,9 @@ rte_vhost_crypto_create(int vid, uint8_t cryptodev_id, vcrypto->sess_pool = sess_pool; vcrypto->cid = cryptodev_id; - vcrypto->cache_session_id =UINT64_MAX ; - vcrypto->last_session_id =1 ; + vcrypto->cache_sym_session_id =UINT64_MAX ; + vcrypto->cache_asym_session_id =UINT64_MAX ; + vcrypto->last_session_id =0 ; vcrypto->dev = dev; vcrypto->option =RTE_VHOST_CRYPTO_ZERO_COPY_DISABLE ;
@@ -1580,6 +2011,9 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, vq = dev->virtqueue[qid]; +if (!vq || !vq->avail) +return 0 ; + avail_idx = *((volatile uint16_t *)&vq->avail->idx); start_idx = vq->last_used_idx; count = avail_idx - start_idx;
lib/vhost/vhost_user.h +29 -4
@@ -99,11 +99,10 @@ typedef struct VhostUserLog {/* Comply with Cryptodev-Linux */ #define VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH 512#define VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH 64 +#define VHOST_USER_CRYPTO_MAX_KEY_LENGTH 1024/* Same structure as vhost-user backend session info */ -typedef struct VhostUserCryptoSessionParam { - int64_t session_id; - uint32_t op_code; +typedef struct VhostUserCryptoSymSessionParam { uint32_t cipher_algo; uint32_t cipher_key_len; uint32_t hash_algo;
@@ -114,10 +113,36 @@ typedef struct VhostUserCryptoSessionParam {uint8_t dir;uint8_t hash_mode;uint8_t chaining_dir; -uint8_t *ciphe_key; +uint8_t *cipher_key;uint8_t *auth_key;uint8_t cipher_key_buf[VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH ];uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH ]; +} VhostUserCryptoSymSessionParam; + + +typedef struct VhostUserCryptoAsymRsaParam { +uint32_t padding_algo; +uint32_t hash_algo; +}VhostUserCryptoAsymRsaParam ; + +typedef struct VhostUserCryptoAsymSessionParam { +uint32_t algo; +uint32_t key_type; +uint32_t key_len; +uint8_t *key; +union { +VhostUserCryptoAsymRsaParam rsa; + } u; +uint8_t key_buf[VHOST_USER_CRYPTO_MAX_KEY_LENGTH ]; +}VhostUserCryptoAsymSessionParam ; + +typedef struct VhostUserCryptoSessionParam { +uint32_t op_code; +union { +VhostUserCryptoSymSessionParam sym_sess; +VhostUserCryptoAsymSessionParam asym_sess; + } u; +uint64_t session_id; }VhostUserCryptoSessionParam ; typedef struct VhostUserVringArea {
Signature · 1 line
2.25.1
Re: [v2 1/2] vhost: add asymmetric RSA support
Quoted 10 lines · Gowrishankar Muthukrishnan
Support asymmetric RSA crypto operations in vhost-user.
Signed-off-by Gowrishankar Muthukrishnan <[email protected]>---
Depends-on: series-34291 ("crypto/virtio: add RSA support")lib/vhost/vhost_crypto.c | 504 ++++++++++++++++++++++++++++++++++++--- lib/vhost/vhost_user.h | 33 ++- 2 files changed, 498 insertions(+), 39 deletions(-)
I'm not a crypto expert, so a second pair of eyes would be welcome. I did not find any obvious bug while reviewing this patch:
PATCH v2 2/2 examples/vhost_crypto: add asymmetric support
In reply to Gowrishankar MuthukrishnanAdd symmetric support.
--- examples/vhost_crypto/main.c | 54 ++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 14 deletions(-)
examples/vhost_crypto/main.c +40 -14
@@ -59,6 +59,7 @@ struct vhost_crypto_options {uint32_t nb_los;uint32_t zero_copy;uint32_t guest_polling; +bool asymmetric_crypto; } options;enum {
@@ -70,6 +71,8 @@ enum {OPT_ZERO_COPY_NUM , #define OPT_POLLING "guest-polling"OPT_POLLING_NUM , +#define OPT_ASYM "asymmetric-crypto" + OPT_ASYM_NUM, };#define NB_SOCKET_FIELDS (2)
@@ -202,9 +205,10 @@ vhost_crypto_usage(const char *prgname)" --%s <lcore>,SOCKET-FILE-PATH\n" " --%s (lcore,cdev_id,queue_id)[,(lcore,cdev_id,queue_id)]\n" " --%s: zero copy\n" -" --%s: guest polling\n" , +" --%s: guest polling\n" +" --%s: asymmetric crypto\n" , prgname,OPT_SOCKET_FILE ,OPT_CONFIG , - OPT_ZERO_COPY, OPT_POLLING); + OPT_ZERO_COPY, OPT_POLLING, OPT_ASYM); } static int
@@ -223,6 +227,8 @@ vhost_crypto_parse_args(int argc, char **argv) NULL, OPT_ZERO_COPY_NUM}, {OPT_POLLING , no_argument, NULL, OPT_POLLING_NUM}, + {OPT_ASYM, no_argument, + NULL, OPT_ASYM_NUM}, {NULL, 0, 0, 0} };
@@ -262,6 +268,10 @@ vhost_crypto_parse_args(int argc, char **argv) options.guest_polling =1 ;break ; +case OPT_ASYM_NUM : + options.asymmetric_crypto = true; +break ; +default :vhost_crypto_usage (prgname);return -EINVAL ;
@@ -362,8 +372,8 @@ destroy_device(int vid) }static const struct rte_vhost_device_ops virtio_crypto_device_ops = { - .new_device = new_device, - .destroy_device = destroy_device, + .new_connection = new_device, + .destroy_connection = destroy_device, }; static int
@@ -376,6 +386,7 @@ vhost_crypto_worker(void *arg)int callfds[VIRTIO_CRYPTO_MAX_NUM_BURST_VQS ];uint32_t lcore_id =rte_lcore_id ();uint32_t burst_size =MAX_PKT_BURST ; +enum rte_crypto_op_type cop_type;uint32_t i, j, k;uint32_t to_fetch, fetched;
@@ -383,9 +394,13 @@ vhost_crypto_worker(void *arg)RTE_LOG (INFO ,USER1 ,"Processing on Core %u started\n" , lcore_id); + cop_type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; +if (options.asymmetric_crypto) + cop_type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; +for (i =0 ; i <NB_VIRTIO_QUEUES ; i++) {if (rte_crypto_op_bulk_alloc (info->cop_pool, -RTE_CRYPTO_OP_TYPE_SYMMETRIC , ops[i], + cop_type, ops[i], burst_size) < burst_size) {RTE_LOG (ERR ,USER1 ,"Failed to alloc cops\n" ); ret =-1 ;
@@ -411,12 +426,11 @@ vhost_crypto_worker(void *arg) fetched);if (unlikely (rte_crypto_op_bulk_alloc ( info->cop_pool, -RTE_CRYPTO_OP_TYPE_SYMMETRIC , + cop_type, ops[j], fetched) < fetched)) {RTE_LOG (ERR ,USER1 ,"Failed realloc\n" );return -1 ; } - fetched = rte_cryptodev_dequeue_burst( info->cid, info->qid, ops_deq[j], RTE_MIN(burst_size,
@@ -477,6 +491,7 @@ main(int argc, char *argv[])struct rte_cryptodev_qp_conf qp_conf;struct rte_cryptodev_config config;struct rte_cryptodev_info dev_info; +enum rte_crypto_op_type cop_type;char name[128 ];uint32_t i, j, lcore;int ret;
@@ -539,12 +554,21 @@ main(int argc, char *argv[]) goto error_exit; } -snprintf (name,127 ,"SESS_POOL_%u" , lo->lcore_id); - info->sess_pool =rte_cryptodev_sym_session_pool_create (name, -SESSION_MAP_ENTRIES , -rte_cryptodev_sym_get_private_session_size ( - info->cid),0 ,0 , -rte_lcore_to_socket_id (lo->lcore_id)); +if (!options.asymmetric_crypto) { +snprintf (name,127 ,"SYM_SESS_POOL_%u" , lo->lcore_id); + info->sess_pool =rte_cryptodev_sym_session_pool_create (name, +SESSION_MAP_ENTRIES , +rte_cryptodev_sym_get_private_session_size ( + info->cid),0 ,0 , +rte_lcore_to_socket_id (lo->lcore_id)); + cop_type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; + }else { +snprintf (name,127 ,"ASYM_SESS_POOL_%u" , lo->lcore_id); + info->sess_pool =rte_cryptodev_asym_session_pool_create (name, +SESSION_MAP_ENTRIES ,0 ,64 , +rte_lcore_to_socket_id (lo->lcore_id)); + cop_type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + }if (!info->sess_pool) {RTE_LOG (ERR ,USER1 ,"Failed to create mempool" );
@@ -553,7 +577,7 @@ main(int argc, char *argv[])snprintf (name,127 ,"COPPOOL_%u" , lo->lcore_id); info->cop_pool =rte_crypto_op_pool_create (name, -RTE_CRYPTO_OP_TYPE_SYMMETRIC ,NB_MEMPOOL_OBJS , + cop_type,NB_MEMPOOL_OBJS ,NB_CACHE_OBJS ,VHOST_CRYPTO_MAX_IV_LEN ,rte_lcore_to_socket_id (lo->lcore_id));
@@ -567,6 +591,8 @@ main(int argc, char *argv[]) qp_conf.nb_descriptors =NB_CRYPTO_DESCRIPTORS ; qp_conf.mp_session = info->sess_pool; +if (options.asymmetric_crypto) + qp_conf.mp_session =NULL ;for (j =0 ; j < dev_info.max_nb_queue_pairs; j++) { ret = rte_cryptodev_queue_pair_setup(info->cid, j,
Signature · 1 line
2.25.1
Re: [v2 2/2] examples/vhost_crypto: add asymmetric support
Quoted 64 lines · Gowrishankar Muthukrishnan
Add symmetric support.
Signed-off-by Gowrishankar Muthukrishnan <[email protected]>--- examples/vhost_crypto/main.c | 54 ++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 14 deletions(-)examples/vhost_crypto/main.c +12
-2@@ -59,6 +59,7 @@ struct vhost_crypto_options {uint32_t nb_los;uint32_t zero_copy;uint32_t guest_polling; +bool asymmetric_crypto; } options;enum {@@ -70,6 +71,8 @@ enum {OPT_ZERO_COPY_NUM , #define OPT_POLLING "guest-polling"OPT_POLLING_NUM , +#define OPT_ASYM "asymmetric-crypto" + OPT_ASYM_NUM, };#define NB_SOCKET_FIELDS (2)@@ -202,9 +205,10 @@ vhost_crypto_usage(const char *prgname)" --%s <lcore>,SOCKET-FILE-PATH\n" " --%s (lcore,cdev_id,queue_id)[,(lcore,cdev_id,queue_id)]\n" " --%s: zero copy\n" -" --%s: guest polling\n" , +" --%s: guest polling\n" +" --%s: asymmetric crypto\n" , prgname,OPT_SOCKET_FILE ,OPT_CONFIG , - OPT_ZERO_COPY, OPT_POLLING); + OPT_ZERO_COPY, OPT_POLLING, OPT_ASYM); } static int@@ -223,6 +227,8 @@ vhost_crypto_parse_args(int argc, char **argv) NULL, OPT_ZERO_COPY_NUM}, {OPT_POLLING , no_argument, NULL, OPT_POLLING_NUM}, + {OPT_ASYM, no_argument, + NULL, OPT_ASYM_NUM}, {NULL, 0, 0, 0} };@@ -262,6 +268,10 @@ vhost_crypto_parse_args(int argc, char **argv) options.guest_polling =1 ;break ; +case OPT_ASYM_NUM : + options.asymmetric_crypto = true; +break ; +default :vhost_crypto_usage (prgname);return -EINVAL ;
examples/vhost_crypto/main.c destroy_device(int vid) · line 376
Quoted 7 lines
examples/vhost_crypto/main.c +2
-2@@ -362,8 +372,8 @@ destroy_device(int vid) }static const struct rte_vhost_device_ops virtio_crypto_device_ops = { - .new_device = new_device, - .destroy_device = destroy_device, + .new_connection = new_device, + .destroy_connection = destroy_device,
It may be worth explaining in the commit message why you are moving from new_device to new_connection.
Quoted 94 lines
examples/vhost_crypto/main.c +26
-10}; static int@@ -376,6 +386,7 @@ vhost_crypto_worker(void *arg)int callfds[VIRTIO_CRYPTO_MAX_NUM_BURST_VQS ];uint32_t lcore_id =rte_lcore_id ();uint32_t burst_size =MAX_PKT_BURST ; +enum rte_crypto_op_type cop_type;uint32_t i, j, k;uint32_t to_fetch, fetched;@@ -383,9 +394,13 @@ vhost_crypto_worker(void *arg)RTE_LOG (INFO ,USER1 ,"Processing on Core %u started\n" , lcore_id); + cop_type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; +if (options.asymmetric_crypto) + cop_type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; +for (i =0 ; i <NB_VIRTIO_QUEUES ; i++) {if (rte_crypto_op_bulk_alloc (info->cop_pool, -RTE_CRYPTO_OP_TYPE_SYMMETRIC , ops[i], + cop_type, ops[i], burst_size) < burst_size) {RTE_LOG (ERR ,USER1 ,"Failed to alloc cops\n" ); ret =-1 ;@@ -411,12 +426,11 @@ vhost_crypto_worker(void *arg) fetched);if (unlikely (rte_crypto_op_bulk_alloc ( info->cop_pool, -RTE_CRYPTO_OP_TYPE_SYMMETRIC , + cop_type, ops[j], fetched) < fetched)) {RTE_LOG (ERR ,USER1 ,"Failed realloc\n" );return -1 ; } - fetched = rte_cryptodev_dequeue_burst( info->cid, info->qid, ops_deq[j], RTE_MIN(burst_size,@@ -477,6 +491,7 @@ main(int argc, char *argv[])struct rte_cryptodev_qp_conf qp_conf;struct rte_cryptodev_config config;struct rte_cryptodev_info dev_info; +enum rte_crypto_op_type cop_type;char name[128 ];uint32_t i, j, lcore;int ret;@@ -539,12 +554,21 @@ main(int argc, char *argv[]) goto error_exit; } -snprintf (name,127 ,"SESS_POOL_%u" , lo->lcore_id); - info->sess_pool =rte_cryptodev_sym_session_pool_create (name, -SESSION_MAP_ENTRIES , -rte_cryptodev_sym_get_private_session_size ( - info->cid),0 ,0 , -rte_lcore_to_socket_id (lo->lcore_id)); +if (!options.asymmetric_crypto) { +snprintf (name,127 ,"SYM_SESS_POOL_%u" , lo->lcore_id); + info->sess_pool =rte_cryptodev_sym_session_pool_create (name, +SESSION_MAP_ENTRIES , +rte_cryptodev_sym_get_private_session_size ( + info->cid),0 ,0 , +rte_lcore_to_socket_id (lo->lcore_id)); + cop_type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; + }else { +snprintf (name,127 ,"ASYM_SESS_POOL_%u" , lo->lcore_id); + info->sess_pool =rte_cryptodev_asym_session_pool_create (name, +SESSION_MAP_ENTRIES ,0 ,64 , +rte_lcore_to_socket_id (lo->lcore_id)); + cop_type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + }if (!info->sess_pool) {RTE_LOG (ERR ,USER1 ,"Failed to create mempool" );@@ -553,7 +577,7 @@ main(int argc, char *argv[])snprintf (name,127 ,"COPPOOL_%u" , lo->lcore_id); info->cop_pool =rte_crypto_op_pool_create (name, -RTE_CRYPTO_OP_TYPE_SYMMETRIC ,NB_MEMPOOL_OBJS , + cop_type,NB_MEMPOOL_OBJS ,NB_CACHE_OBJS ,VHOST_CRYPTO_MAX_IV_LEN ,rte_lcore_to_socket_id (lo->lcore_id));@@ -567,6 +591,8 @@ main(int argc, char *argv[]) qp_conf.nb_descriptors =NB_CRYPTO_DESCRIPTORS ; qp_conf.mp_session = info->sess_pool; +if (options.asymmetric_crypto) + qp_conf.mp_session =NULL ;for (j =0 ; j < dev_info.max_nb_queue_pairs; j++) { ret = rte_cryptodev_queue_pair_setup(info->cid, j,
RE: [EXTERNAL] Re: [v2 2/2] examples/vhost_crypto: add asymmetric support
Hi Maxime,
Quoted 7 lines
examples/vhost_crypto/main.c destroy_device(int vid) · line 376
Quoted 5 lines
static const struct rte_vhost_device_ops virtio_crypto_device_ops = {examples/vhost_crypto/main.c +2
-2- .new_device = new_device, - .destroy_device = destroy_device, + .new_connection = new_device, + .destroy_connection = destroy_device,It may be worth explaining in the commit message why you are moving from
new_devicetonew_connection.
This change is required when this backend application runs in server mode.
I understand this change is irrelevant to the scope of this patch and will be taken out in a separate patch (in the new version of this series).
Thanks,
Gowrishankar
Quoted 107 lines
Quoted 28 lines
};static int
examples/vhost_crypto/main.c +6
-1@@ -376,6 +386,7 @@ vhost_crypto_worker(void *arg)int callfds[VIRTIO_CRYPTO_MAX_NUM_BURST_VQS ];uint32_t lcore_id =rte_lcore_id ();uint32_t burst_size =MAX_PKT_BURST ; +enum rte_crypto_op_type cop_type;uint32_t i, j, k;uint32_t to_fetch, fetched;@@ -383,9 +394,13 @@ vhost_crypto_worker(void *arg)RTE_LOG (INFO ,USER1 ,"Processing on Core %u started\n" , lcore_id); + cop_type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; +if (options.asymmetric_crypto) + cop_type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; +for (i =0 ; i <NB_VIRTIO_QUEUES ; i++) {if (rte_crypto_op_bulk_alloc (info->cop_pool, -RTE_CRYPTO_OP_TYPE_SYMMETRIC , ops[i], + cop_type, ops[i], burst_size) < burst_size) {RTE_LOG (ERR ,USER1 ,"Failed to alloc cops\n" ); ret =-1 ;examples/vhost_crypto/main.c vhost_crypto_worker(void *arg) · line 414
Quoted 4 lines
examples/vhost_crypto/main.c +0
-1@@ -411,12 +426,11 @@ vhost_crypto_worker(void *arg) fetched); if (unlikely(rte_crypto_op_bulk_alloc( info->cop_pool, -
RTE_CRYPTO_OP_TYPE_SYMMETRIC,examples/vhost_crypto/main.c vhost_crypto_worker(void *arg)
Quoted 3 lines
examples/vhost_crypto/main.c +1
-0+ cop_type, ops[j], fetched) < fetched)) { RTE_LOG(ERR, USER1, "Failedrealloc\n");
examples/vhost_crypto/main.c vhost_crypto_worker(void *arg)
Quoted 6 lines
examples/vhost_crypto/main.c +0
-1return -1 ; } - fetched = rte_cryptodev_dequeue_burst( info->cid, info->qid, ops_deq[j],RTE_MIN(burst_size, @@ -477,6 +491,7 @@ main(int
Quoted 9 lines
argc, char *argv[])
structrte_cryptodev_qp_confqp_conf;
structrte_cryptodev_configconfig;
structrte_cryptodev_infodev_info;examples/vhost_crypto/main.c +1
-0+enum rte_crypto_op_type cop_type;char name[128 ];uint32_t i, j, lcore;int ret;examples/vhost_crypto/main.c main(int argc, char *argv[]) · line 543
Quoted 5 lines
examples/vhost_crypto/main.c +0
-2@@ -539,12 +554,21 @@ main(int argc, char *argv[]) goto error_exit; } -snprintf (name,127 ,"SESS_POOL_%u" , lo->lcore_id); - info->sess_pool =rte_cryptodev_sym_session_pool_create(name,
examples/vhost_crypto/main.c main(int argc, char *argv[])
Quoted 8 lines
examples/vhost_crypto/main.c +3
-4-SESSION_MAP_ENTRIES , -rte_cryptodev_sym_get_private_session_size ( - info->cid),0 ,0 , - rte_lcore_to_socket_id(lo->lcore_id)); +if (!options.asymmetric_crypto) { +snprintf (name,127 ,"SYM_SESS_POOL_%u" , lo- lcore_id); + info->sess_pool =rte_cryptodev_sym_session_pool_create(name,
Review main(int argc, char *argv[]) · line 562
Quoted 2 lines
(quoted diff) +2
-0+ SESSION_MAP_ENTRIES, +rte_cryptodev_sym_get_private_session_size(examples/vhost_crypto/main.c main(int argc, char *argv[])
Quoted 7 lines
examples/vhost_crypto/main.c +6
-0+ info->cid), 0, 0, + rte_lcore_to_socket_id(lo->lcore_id)); + cop_type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; + }else { +snprintf (name,127 ,"ASYM_SESS_POOL_%u" , lo- lcore_id); + info->sess_pool =rte_cryptodev_asym_session_pool_create(name,
Quoted 7 lines
examples/vhost_crypto/main.c +4
-0+SESSION_MAP_ENTRIES ,0 ,64 , + rte_lcore_to_socket_id(lo->lcore_id)); + cop_type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + }if (!info->sess_pool) { RTE_LOG(ERR, USER1, "Failed to create mempool");@@ -553,7 +577,7
examples/vhost_crypto/main.c vhost_crypto_worker(void *arg) · line 414
Quoted 5 lines
@@
main(int argc, char *argv[])snprintf(name, 127, "COPPOOL_%u", lo->lcore_id); info->cop_pool = rte_crypto_op_pool_create(name,examples/vhost_crypto/main.c +0
-1- RTE_CRYPTO_OP_TYPE_SYMMETRIC,
NB_MEMPOOL_OBJS,Review
Quoted 2 lines
(quoted diff) +1
-0+ cop_type, NB_MEMPOOL_OBJS, NB_CACHE_OBJS,
VHOST_CRYPTO_MAX_IV_LEN,Quoted 11 lines
rte_lcore_to_socket_id(lo->lcore_id));examples/vhost_crypto/main.c +2
-0@@ -567,6 +591,8 @@ main(int argc, char *argv[]) qp_conf.nb_descriptors =NB_CRYPTO_DESCRIPTORS ; qp_conf.mp_session = info->sess_pool; +if (options.asymmetric_crypto) + qp_conf.mp_session =NULL ;for (j =0 ; j < dev_info.max_nb_queue_pairs; j++) { ret = rte_cryptodev_queue_pair_setup(info->cid, j,
v3 cover vhost: add RSA support
In reply to Gowrishankar MuthukrishnanThis patch series supports asymmetric RSA in vhost crypto library. It also includes changes to improve vhost crypto library:
* support newer QEMU versions.
* fix broken vhost_crypto example application.
* stabilize crypto fastpath operations.
v3:
- spin off new patches from one single patch in v2.
- stabilized vhost crypto lib and example app.
Gowrishankar Muthukrishnan (5):
vhost: skip crypto op fetch before vring init
vhost: update vhost_user crypto session parameters examples/vhost_crypto: fix user callbacks
vhost: support asymmetric RSA crypto ops examples/vhost_crypto: support asymmetric crypto
examples/vhost_crypto/main.c | 54 +++- lib/vhost/vhost_crypto.c | 514 ++++++++++++++++++++++++++++++++--- lib/vhost/vhost_user.h | 33 ++- lib/vhost/virtio_crypto.h | 67 +++++ 4 files changed, 609 insertions(+), 59 deletions(-)
Signature · 1 line
2.25.1
PATCH v3 1/5 vhost: skip crypto op fetch before vring init
Until virtio avail ring is initialized (by VHOST_USER_SET_VRING_ADDR), worker thread should not try to fetch crypto op, which would lead to memory fault.
--- lib/vhost/vhost_crypto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
lib/vhost/vhost_crypto.c +10 -0
@@ -1580,6 +1580,16 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, vq = dev->virtqueue[qid]; +if (unlikely (vq ==NULL )) { +VC_LOG_ERR ("Invalid virtqueue %u" , qid); +return 0 ; + } + +if (unlikely (vq->avail ==NULL )) { +VC_LOG_DBG ("Virtqueue ring not yet initialized %u" , qid); +return 0 ; + } + avail_idx = *((volatile uint16_t *)&vq->avail->idx); start_idx = vq->last_used_idx; count = avail_idx - start_idx;
Signature · 1 line
2.25.1
PATCH v3 2/5 vhost: update vhost_user crypto session parameters
In reply to Gowrishankar MuthukrishnanAs per requirements on vhost_user spec, session id should be located at the end of session parameter.
Update VhostUserCryptoSessionParam structure to support newer QEMU. Due to additional parameters added in QEMU, received payload from QEMU would be larger than existing payload, hence breaks parsing vhost_user message.
This patch addresses both of the above problems.
---
v3:
- decoupled originally from v2 series single patch.
---
lib/vhost/vhost_crypto.c | 12 ++++++------ lib/vhost/vhost_user.h | 33 +++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-)
lib/vhost/vhost_crypto.c +6 -6
@@ -237,7 +237,7 @@ struct vhost_crypto_data_req {static int transform_cipher_param (struct rte_crypto_sym_xform *xform, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {int ret;
@@ -273,7 +273,7 @@ transform_cipher_param(struct rte_crypto_sym_xform *xform,static int transform_chain_param (struct rte_crypto_sym_xform *xforms, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {struct rte_crypto_sym_xform *xform_cipher, *xform_auth;int ret;
@@ -341,10 +341,10 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto,struct rte_cryptodev_sym_session *session;int ret; -switch (sess_param->op_type) { +switch (sess_param->u.sym_sess.op_type) {case VIRTIO_CRYPTO_SYM_OP_NONE :case VIRTIO_CRYPTO_SYM_OP_CIPHER : - ret =transform_cipher_param (&xform1, sess_param); + ret =transform_cipher_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session msg (%i)" , ret); sess_param->session_id = ret;
@@ -352,7 +352,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, }break ;case VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING : -if (unlikely (sess_param->hash_mode != +if (unlikely (sess_param->u.sym_sess.hash_mode !=VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH )) { sess_param->session_id = -VIRTIO_CRYPTO_NOTSUPP ; VC_LOG_ERR("Error transform session message (%i)",
@@ -362,7 +362,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, xform1.next = &xform2; - ret =transform_chain_param (&xform1, sess_param); + ret =transform_chain_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session message (%i)" , ret); sess_param->session_id = ret;
lib/vhost/vhost_user.h +29 -4
@@ -99,11 +99,10 @@ typedef struct VhostUserLog {/* Comply with Cryptodev-Linux */ #define VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH 512#define VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH 64 +#define VHOST_USER_CRYPTO_MAX_KEY_LENGTH 1024/* Same structure as vhost-user backend session info */ -typedef struct VhostUserCryptoSessionParam { - int64_t session_id; - uint32_t op_code; +typedef struct VhostUserCryptoSymSessionParam { uint32_t cipher_algo; uint32_t cipher_key_len; uint32_t hash_algo;
@@ -114,10 +113,36 @@ typedef struct VhostUserCryptoSessionParam {uint8_t dir;uint8_t hash_mode;uint8_t chaining_dir; -uint8_t *ciphe_key; +uint8_t *cipher_key;uint8_t *auth_key;uint8_t cipher_key_buf[VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH ];uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH ]; +} VhostUserCryptoSymSessionParam; + + +typedef struct VhostUserCryptoAsymRsaParam { +uint32_t padding_algo; +uint32_t hash_algo; +}VhostUserCryptoAsymRsaParam ; + +typedef struct VhostUserCryptoAsymSessionParam { +uint32_t algo; +uint32_t key_type; +uint32_t key_len; +uint8_t *key; +union { +VhostUserCryptoAsymRsaParam rsa; + } u; +uint8_t key_buf[VHOST_USER_CRYPTO_MAX_KEY_LENGTH ]; +}VhostUserCryptoAsymSessionParam ; + +typedef struct VhostUserCryptoSessionParam { +uint32_t op_code; +union { +VhostUserCryptoSymSessionParam sym_sess; +VhostUserCryptoAsymSessionParam asym_sess; + } u; +int64_t session_id; }VhostUserCryptoSessionParam ; typedef struct VhostUserVringArea {
Signature · 1 line
2.25.1
PATCH v3 3/5 examples/vhost_crypto: fix user callbacks
In reply to Gowrishankar MuthukrishnanIn order to handle new vhost user connection, use new_connection and destroy_connection callbacks.
---
v3:
- decoupled from v2 single patch.
--- examples/vhost_crypto/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
examples/vhost_crypto/main.c +2 -2
@@ -362,8 +362,8 @@ destroy_device(int vid) }static const struct rte_vhost_device_ops virtio_crypto_device_ops = { - .new_device = new_device, - .destroy_device = destroy_device, + .new_connection = new_device, + .destroy_connection = destroy_device, }; static int
Signature · 1 line
2.25.1
PATCH v3 4/5 vhost: support asymmetric RSA crypto ops
In reply to Gowrishankar MuthukrishnanSupport asymmetric RSA crypto operations in vhost-user.
---
v3:
- TLV decode optimization for fast path.
- virtio_crypto.h changes moved from virtio PMD patch series into this series as asymmetric support starts essentially from library.
---
lib/vhost/vhost_crypto.c | 492 +++++++++++++++++++++++++++++++++++--- lib/vhost/virtio_crypto.h | 67 ++++++ 2 files changed, 524 insertions(+), 35 deletions(-)
lib/vhost/vhost_crypto.c +457 -35
@@ -54,6 +54,14 @@ RTE_LOG_REGISTER_SUFFIX(vhost_crypto_logtype, crypto, INFO);*/ #define vhost_crypto_desc vring_desc +struct vhost_crypto_session { +union { +struct rte_cryptodev_asym_session *asym; +struct rte_cryptodev_sym_session *sym; + }; +enum rte_crypto_op_type type; +}; +static int cipher_algo_transform (uint32_t virtio_cipher_algo,enum rte_crypto_cipher_algorithm *algo)
@@ -206,8 +214,10 @@ struct __rte_cache_aligned vhost_crypto {uint64_t last_session_id; -uint64_t cache_session_id; -struct rte_cryptodev_sym_session *cache_session; +uint64_t cache_sym_session_id; +struct rte_cryptodev_sym_session *cache_sym_session; +uint64_t cache_asym_session_id; +struct rte_cryptodev_asym_session *cache_asym_session;/** socket id for the device */ int socket_id;
@@ -334,10 +344,11 @@ transform_chain_param(struct rte_crypto_sym_xform *xforms, }static void -vhost_crypto_create_sess (struct vhost_crypto *vcrypto, +vhost_crypto_create_sym_sess (struct vhost_crypto *vcrypto,VhostUserCryptoSessionParam *sess_param) {struct rte_crypto_sym_xform xform1 = {0 }, xform2 = {0 }; +struct vhost_crypto_session *vhost_session;struct rte_cryptodev_sym_session *session;int ret;
@@ -384,42 +395,277 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto,return ; } -/* insert hash to map */ -if (rte_hash_add_key_data (vcrypto->session_map, - &vcrypto->last_session_id, session) <0 ) { + vhost_session =rte_zmalloc (NULL ,sizeof (*vhost_session),0 ); +if (vhost_session ==NULL ) { +VC_LOG_ERR ("Failed to alloc session memory" ); + goto error_exit; + } + + vhost_session->type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; + vhost_session->sym = session; + +/* insert session to map */ +if ((rte_hash_add_key_data (vcrypto->session_map, + &vcrypto->last_session_id, vhost_session) <0 )) {VC_LOG_ERR ("Failed to insert session to hash table" ); + goto error_exit; + } + +VC_LOG_INFO ("Session %" PRIu64" created for vdev %i." , + vcrypto->last_session_id, vcrypto->dev->vid); + + sess_param->session_id = vcrypto->last_session_id; + vcrypto->last_session_id++; +return ; + +error_exit: +if (rte_cryptodev_sym_session_free (vcrypto->cid, session) <0 ) +VC_LOG_ERR ("Failed to free session" ); + + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +rte_free (vhost_session); +} + +static int +tlv_decode (uint8_t *tlv,uint8_t type,uint8_t **data,size_t *data_len) +{ +size_t tlen = -EINVAL , len; + +if (tlv[0 ] != type) +return -EINVAL ; + +if (tlv[1 ] ==0x82 ) { + len = (tlv[2 ] <<8 ) | tlv[3 ]; + *data = &tlv[4 ]; + tlen = len +4 ; + }else if (tlv[1 ] ==0x81 ) { + len = tlv[2 ]; + *data = &tlv[3 ]; + tlen = len +3 ; + }else { + len = tlv[1 ]; + *data = &tlv[2 ]; + tlen = len +2 ; + } + + *data_len = len; +return tlen; +} + +static int +virtio_crypto_asym_rsa_der_to_xform (uint8_t *der,size_t der_len, +struct rte_crypto_asym_xform *xform) +{ +uint8_t *n =NULL , *e =NULL , *d =NULL , *p =NULL , *q =NULL , *dp =NULL , + *dq =NULL , *qinv =NULL , *v =NULL , *tlv; +size_t nlen, elen, dlen, plen, qlen, dplen, dqlen, qinvlen, vlen; +int len; + +RTE_SET_USED (der_len); + +if (der[0 ] !=0x30 ) +return -EINVAL ; + +if (der[1 ] ==0x82 ) + tlv = &der[4 ]; +else if (der[1 ] ==0x81 ) + tlv = &der[3 ]; +else +return -EINVAL ; + + len =tlv_decode (tlv,0x02 , &v, &vlen); +if (len <0 || v[0 ] !=0x0 || vlen !=1 ) +return -EINVAL ; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &n, &nlen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &e, &elen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &d, &dlen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &p, &plen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &q, &qlen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &dp, &dplen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &dq, &dqlen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &qinv, &qinvlen); +if (len <0 ) +return len; + + xform->rsa.n.data = n; + xform->rsa.n.length = nlen; + xform->rsa.e.data = e; + xform->rsa.e.length = elen; + xform->rsa.d.data = d; + xform->rsa.d.length = dlen; + xform->rsa.qt.p.data = p; + xform->rsa.qt.p.length = plen; + xform->rsa.qt.q.data = q; + xform->rsa.qt.q.length = qlen; + xform->rsa.qt.dP.data = dp; + xform->rsa.qt.dP.length = dplen; + xform->rsa.qt.dQ.data = dq; + xform->rsa.qt.dQ.length = dqlen; + xform->rsa.qt.qInv.data = qinv; + xform->rsa.qt.qInv.length = qinvlen; + +RTE_ASSERT ((tlv + len - &der[0 ]) == der_len); +return 0 ; +} + +static int +rsa_param_transform (struct rte_crypto_asym_xform *xform, +VhostUserCryptoAsymSessionParam *param) +{ +int ret; -if (rte_cryptodev_sym_session_free (vcrypto->cid, session) <0 ) -VC_LOG_ERR ("Failed to free session" ); + ret =virtio_crypto_asym_rsa_der_to_xform (param->key_buf, param->key_len, xform); +if (ret <0 ) +return ret; + +switch (param->u.rsa.padding_algo) { +case VIRTIO_CRYPTO_RSA_RAW_PADDING : + xform->rsa.padding.type =RTE_CRYPTO_RSA_PADDING_NONE ; +break ; +case VIRTIO_CRYPTO_RSA_PKCS1_PADDING : + xform->rsa.padding.type =RTE_CRYPTO_RSA_PADDING_PKCS1_5 ; +break ; +default : +VC_LOG_ERR ("Unknown padding type" ); +return -EINVAL ; + } + + xform->rsa.key_type =RTE_RSA_KEY_TYPE_QT ; + xform->xform_type =RTE_CRYPTO_ASYM_XFORM_RSA ; +return 0 ; +} + +static void +vhost_crypto_create_asym_sess (struct vhost_crypto *vcrypto, +VhostUserCryptoSessionParam *sess_param) +{ +struct rte_cryptodev_asym_session *session =NULL ; +struct vhost_crypto_session *vhost_session; +struct rte_crypto_asym_xform xform = {0 }; +int ret; + +switch (sess_param->u.asym_sess.algo) { +case VIRTIO_CRYPTO_AKCIPHER_RSA : + ret =rsa_param_transform (&xform, &sess_param->u.asym_sess); +if (unlikely (ret <0 )) { +VC_LOG_ERR ("Error transform session msg (%i)" , ret); + sess_param->session_id = ret; +return ; + } +break ; +default : +VC_LOG_ERR ("Invalid op algo" ); sess_param->session_id = -VIRTIO_CRYPTO_ERR ;return ; } + ret =rte_cryptodev_asym_session_create (vcrypto->cid, &xform, + vcrypto->sess_pool, (void *)&session); +if (session ==NULL ) { +VC_LOG_ERR ("Failed to create session" ); + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +return ; + } + + vhost_session =rte_zmalloc (NULL ,sizeof (*vhost_session),0 ); +if (vhost_session ==NULL ) { +VC_LOG_ERR ("Failed to alloc session memory" ); + goto error_exit; + } + + vhost_session->type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + vhost_session->asym = session; + +/* insert session to map */ +if ((rte_hash_add_key_data (vcrypto->session_map, + &vcrypto->last_session_id, vhost_session) <0 )) { +VC_LOG_ERR ("Failed to insert session to hash table" ); + goto error_exit; + } +VC_LOG_INFO ("Session %" PRIu64" created for vdev %i." , vcrypto->last_session_id, vcrypto->dev->vid); sess_param->session_id = vcrypto->last_session_id; vcrypto->last_session_id++; +return ; + +error_exit: +if (rte_cryptodev_asym_session_free (vcrypto->cid, session) <0 ) +VC_LOG_ERR ("Failed to free session" ); + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +rte_free (vhost_session); +} + +static void +vhost_crypto_create_sess (struct vhost_crypto *vcrypto, +VhostUserCryptoSessionParam *sess_param) +{ +if (sess_param->op_code ==VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION ) +vhost_crypto_create_asym_sess (vcrypto, sess_param); +else +vhost_crypto_create_sym_sess (vcrypto, sess_param); }static int vhost_crypto_close_sess (struct vhost_crypto *vcrypto,uint64_t session_id) { -struct rte_cryptodev_sym_session *session; +struct vhost_crypto_session *vhost_session =NULL ;uint64_t sess_id = session_id;int ret; ret =rte_hash_lookup_data (vcrypto->session_map, &sess_id, - (void **)&session); - + (void **)&vhost_session);if (unlikely (ret <0 )) { -VC_LOG_ERR ("Failed to delete session %" PRIu64"." , session_id); +VC_LOG_ERR ("Failed to find session for id %" PRIu64"." , session_id);return -VIRTIO_CRYPTO_INVSESS ; } -if (rte_cryptodev_sym_session_free (vcrypto->cid, session) <0 ) { -VC_LOG_DBG ("Failed to free session" ); -return -VIRTIO_CRYPTO_ERR ; +if (vhost_session->type ==RTE_CRYPTO_OP_TYPE_SYMMETRIC ) { +if (rte_cryptodev_sym_session_free (vcrypto->cid, + vhost_session->sym) <0 ) { +VC_LOG_DBG ("Failed to free session" ); +return -VIRTIO_CRYPTO_ERR ; + } + }else if (vhost_session->type ==RTE_CRYPTO_OP_TYPE_ASYMMETRIC ) { +if (rte_cryptodev_asym_session_free (vcrypto->cid, + vhost_session->asym) <0 ) { +VC_LOG_DBG ("Failed to free session" ); +return -VIRTIO_CRYPTO_ERR ; + } + }else { +VC_LOG_ERR ("Invalid session for id %" PRIu64"." , session_id); +return -VIRTIO_CRYPTO_INVSESS ; }if (rte_hash_del_key (vcrypto->session_map, &sess_id) <0 ) {
@@ -430,6 +676,7 @@ vhost_crypto_close_sess(struct vhost_crypto *vcrypto, uint64_t session_id)VC_LOG_INFO ("Session %" PRIu64" deleted for vdev %i." , sess_id, vcrypto->dev->vid); +rte_free (vhost_session);return 0 ; }
@@ -1123,6 +1370,115 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,return ret; } +static __rte_always_inline uint8_t +vhost_crypto_check_akcipher_request (struct virtio_crypto_akcipher_data_req *req) +{ +RTE_SET_USED (req); +return VIRTIO_CRYPTO_OK ; +} + +static __rte_always_inline uint8_t +prepare_asym_rsa_op (struct vhost_crypto *vcrypto,struct rte_crypto_op *op, +struct vhost_crypto_data_req *vc_req, +struct virtio_crypto_op_data_req *req, +struct vhost_crypto_desc *head, +uint32_t max_n_descs) +{ +struct rte_crypto_rsa_op_param *rsa = &op->asym->rsa; +struct vhost_crypto_desc *desc = head; +uint8_t ret =VIRTIO_CRYPTO_ERR ; +uint16_t wlen =0 ; + +/* prepare */ +switch (vcrypto->option) { +case RTE_VHOST_CRYPTO_ZERO_COPY_DISABLE : + vc_req->wb_pool = vcrypto->wb_pool; +if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_SIGN ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_SIGN ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.src_data_len; + rsa->sign.length = req->u.akcipher_req.para.dst_data_len; + wlen = rsa->sign.length; + desc =find_write_desc (head, desc, max_n_descs); +if (unlikely (!desc)) { +VC_LOG_ERR ("Cannot find write location" ); + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + rsa->sign.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RW ); +if (unlikely (rsa->sign.data ==NULL )) { + ret =VIRTIO_CRYPTO_ERR ; + goto error_exit; + } + + desc +=1 ; + }else if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_VERIFY ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_VERIFY ; + rsa->sign.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->sign.length = req->u.akcipher_req.para.src_data_len; + desc +=1 ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.dst_data_len; + desc +=1 ; + }else if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_ENCRYPT ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_ENCRYPT ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.src_data_len; + rsa->cipher.length = req->u.akcipher_req.para.dst_data_len; + wlen = rsa->cipher.length; + desc =find_write_desc (head, desc, max_n_descs); +if (unlikely (!desc)) { +VC_LOG_ERR ("Cannot find write location" ); + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + rsa->cipher.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RW ); +if (unlikely (rsa->cipher.data ==NULL )) { + ret =VIRTIO_CRYPTO_ERR ; + goto error_exit; + } + + desc +=1 ; + }else if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_DECRYPT ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_DECRYPT ; + rsa->cipher.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->cipher.length = req->u.akcipher_req.para.src_data_len; + desc +=1 ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.dst_data_len; + desc +=1 ; + }else { + goto error_exit; + } +break ; +case RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE : +default : + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + op->type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + op->sess_type =RTE_CRYPTO_OP_WITH_SESSION ; + + vc_req->inhdr =get_data_ptr (vc_req, desc,VHOST_ACCESS_WO ); +if (unlikely (vc_req->inhdr ==NULL )) { + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + vc_req->inhdr->status =VIRTIO_CRYPTO_OK ; + vc_req->len = wlen +INHDR_LEN ; +return 0 ; +error_exit: +if (vc_req->wb) +free_wb_data (vc_req->wb, vc_req->wb_pool); + + vc_req->len =INHDR_LEN ; +return ret; +} +/** * Process on descriptor */
@@ -1133,17 +1489,21 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, uint16_t desc_idx) __rte_no_thread_safety_analysis/* FIXME: requires iotlb_lock? */ { -struct vhost_crypto_data_req *vc_req =rte_mbuf_to_priv (op->sym->m_src); -struct rte_cryptodev_sym_session *session; +struct vhost_crypto_data_req *vc_req, *vc_req_out; +struct rte_cryptodev_asym_session *asym_session; +struct rte_cryptodev_sym_session *sym_session; +struct vhost_crypto_session *vhost_session; +struct vhost_crypto_desc *desc = descs; +uint32_t nb_descs =0 , max_n_descs, i; +struct vhost_crypto_data_req data_req;struct virtio_crypto_op_data_req req;struct virtio_crypto_inhdr *inhdr; -struct vhost_crypto_desc *desc = descs;struct vring_desc *src_desc;uint64_t session_id;uint64_t dlen; -uint32_t nb_descs =0 , max_n_descs, i;int err; + vc_req = &data_req; vc_req->desc_idx = desc_idx; vc_req->dev = vcrypto->dev; vc_req->vq = vq;
@@ -1226,12 +1586,14 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto,switch (req.header.opcode) {case VIRTIO_CRYPTO_CIPHER_ENCRYPT :case VIRTIO_CRYPTO_CIPHER_DECRYPT : + vc_req_out =rte_mbuf_to_priv (op->sym->m_src); +memcpy (vc_req_out, vc_req,sizeof (struct vhost_crypto_data_req )); session_id = req.header.session_id;/* one branch to avoid unnecessary table lookup */ -if (vcrypto->cache_session_id != session_id) { +if (vcrypto->cache_sym_session_id != session_id) { err =rte_hash_lookup_data (vcrypto->session_map, - &session_id, (void **)&session); + &session_id, (void **)&vhost_session);if (unlikely (err <0 )) { err =VIRTIO_CRYPTO_ERR ; VC_LOG_ERR("Failed to find session %"PRIu64,
@@ -1239,13 +1601,14 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, goto error_exit; } - vcrypto->cache_session = session; - vcrypto->cache_session_id = session_id; + vcrypto->cache_sym_session = vhost_session->sym; + vcrypto->cache_sym_session_id = session_id; } - session = vcrypto->cache_session; + sym_session = vcrypto->cache_sym_session; + op->type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; - err =rte_crypto_op_attach_sym_session (op, session); + err =rte_crypto_op_attach_sym_session (op, sym_session);if (unlikely (err <0 )) { err =VIRTIO_CRYPTO_ERR ;VC_LOG_ERR ("Failed to attach session to op" );
@@ -1257,12 +1620,12 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, err =VIRTIO_CRYPTO_NOTSUPP ;break ;case VIRTIO_CRYPTO_SYM_OP_CIPHER : - err =prepare_sym_cipher_op (vcrypto, op, vc_req, + err =prepare_sym_cipher_op (vcrypto, op, vc_req_out, &req.u.sym_req.u.cipher, desc, max_n_descs);break ;case VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING : - err =prepare_sym_chain_op (vcrypto, op, vc_req, + err =prepare_sym_chain_op (vcrypto, op, vc_req_out, &req.u.sym_req.u.chain, desc, max_n_descs);break ;
@@ -1271,6 +1634,53 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto,VC_LOG_ERR ("Failed to process sym request" ); goto error_exit; } +break ; +case VIRTIO_CRYPTO_AKCIPHER_SIGN : +case VIRTIO_CRYPTO_AKCIPHER_VERIFY : +case VIRTIO_CRYPTO_AKCIPHER_ENCRYPT : +case VIRTIO_CRYPTO_AKCIPHER_DECRYPT : + session_id = req.header.session_id; + +/* one branch to avoid unnecessary table lookup */ +if (vcrypto->cache_asym_session_id != session_id) { + err =rte_hash_lookup_data (vcrypto->session_map, + &session_id, (void **)&vhost_session); +if (unlikely (err <0 )) { + err =VIRTIO_CRYPTO_ERR ; +VC_LOG_ERR ("Failed to find asym session %" PRIu64, + session_id); + goto error_exit; + } + + vcrypto->cache_asym_session = vhost_session->asym; + vcrypto->cache_asym_session_id = session_id; + } + + asym_session = vcrypto->cache_asym_session; + op->type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + + err =rte_crypto_op_attach_asym_session (op, asym_session); +if (unlikely (err <0 )) { + err =VIRTIO_CRYPTO_ERR ; +VC_LOG_ERR ("Failed to attach asym session to op" ); + goto error_exit; + } + + vc_req_out =rte_cryptodev_asym_session_get_user_data (asym_session); +rte_memcpy (vc_req_out, vc_req,sizeof (struct vhost_crypto_data_req )); + vc_req_out->wb =NULL ; + +switch (req.header.algo) { +case VIRTIO_CRYPTO_AKCIPHER_RSA : + err =prepare_asym_rsa_op (vcrypto, op, vc_req_out, + &req, desc, max_n_descs); +break ; + } +if (unlikely (err !=0 )) { +VC_LOG_ERR ("Failed to process asym request" ); + goto error_exit; + } +break ;default : err =VIRTIO_CRYPTO_ERR ;
@@ -1294,12 +1704,22 @@ static __rte_always_inline struct vhost_virtqueue * vhost_crypto_finalize_one_request(struct rte_crypto_op *op, struct vhost_virtqueue *old_vq) { - struct rte_mbuf *m_src = op->sym->m_src; -struct rte_mbuf *m_dst = op->sym->m_dst; -struct vhost_crypto_data_req *vc_req =rte_mbuf_to_priv (m_src); + struct rte_mbuf *m_src = NULL, *m_dst = NULL; +struct vhost_crypto_data_req *vc_req;struct vhost_virtqueue *vq;uint16_t used_idx, desc_idx; +if (op->type ==RTE_CRYPTO_OP_TYPE_SYMMETRIC ) { + m_src = op->sym->m_src; + m_dst = op->sym->m_dst; + vc_req =rte_mbuf_to_priv (m_src); + }else if (op->type ==RTE_CRYPTO_OP_TYPE_ASYMMETRIC ) { + vc_req =rte_cryptodev_asym_session_get_user_data (op->asym->session); + }else { +VC_LOG_ERR ("Invalid crypto op type" ); +return NULL ; + } +if (unlikely (!vc_req)) {VC_LOG_ERR ("Failed to retrieve vc_req" );return NULL ;
@@ -1321,10 +1741,11 @@ vhost_crypto_finalize_one_request(struct rte_crypto_op *op, vq->used->ring[desc_idx].id = vq->avail->ring[desc_idx]; vq->used->ring[desc_idx].len = vc_req->len; -rte_mempool_put (m_src->pool, (void *)m_src); - -if (m_dst) -rte_mempool_put (m_dst->pool, (void *)m_dst); +if (op->type ==RTE_CRYPTO_OP_TYPE_SYMMETRIC ) { +rte_mempool_put (m_src->pool, (void *)m_src); +if (m_dst) +rte_mempool_put (m_dst->pool, (void *)m_dst); + }return vc_req->vq; }
@@ -1407,7 +1828,8 @@ rte_vhost_crypto_create(int vid, uint8_t cryptodev_id, vcrypto->sess_pool = sess_pool; vcrypto->cid = cryptodev_id; - vcrypto->cache_session_id =UINT64_MAX ; + vcrypto->cache_sym_session_id =UINT64_MAX ; + vcrypto->cache_asym_session_id =UINT64_MAX ; vcrypto->last_session_id =1 ; vcrypto->dev = dev; vcrypto->option =RTE_VHOST_CRYPTO_ZERO_COPY_DISABLE ;
lib/vhost/virtio_crypto.h +67 -0
115 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v3 5/5 examples/vhost_crypto: support asymmetric crypto
In reply to Gowrishankar MuthukrishnanSupport asymmetric crypto operations.
--- examples/vhost_crypto/main.c | 50 +++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-)
examples/vhost_crypto/main.c +38 -12
@@ -59,6 +59,7 @@ struct vhost_crypto_options {uint32_t nb_los;uint32_t zero_copy;uint32_t guest_polling; +bool asymmetric_crypto; } options;enum {
@@ -70,6 +71,8 @@ enum {OPT_ZERO_COPY_NUM , #define OPT_POLLING "guest-polling"OPT_POLLING_NUM , +#define OPT_ASYM "asymmetric-crypto" + OPT_ASYM_NUM, };#define NB_SOCKET_FIELDS (2)
@@ -202,9 +205,10 @@ vhost_crypto_usage(const char *prgname)" --%s <lcore>,SOCKET-FILE-PATH\n" " --%s (lcore,cdev_id,queue_id)[,(lcore,cdev_id,queue_id)]\n" " --%s: zero copy\n" -" --%s: guest polling\n" , +" --%s: guest polling\n" +" --%s: asymmetric crypto\n" , prgname,OPT_SOCKET_FILE ,OPT_CONFIG , - OPT_ZERO_COPY, OPT_POLLING); + OPT_ZERO_COPY, OPT_POLLING, OPT_ASYM); } static int
@@ -223,6 +227,8 @@ vhost_crypto_parse_args(int argc, char **argv) NULL, OPT_ZERO_COPY_NUM}, {OPT_POLLING , no_argument, NULL, OPT_POLLING_NUM}, + {OPT_ASYM, no_argument, + NULL, OPT_ASYM_NUM}, {NULL, 0, 0, 0} };
@@ -262,6 +268,10 @@ vhost_crypto_parse_args(int argc, char **argv) options.guest_polling =1 ;break ; +case OPT_ASYM_NUM : + options.asymmetric_crypto = true; +break ; +default :vhost_crypto_usage (prgname);return -EINVAL ;
@@ -376,6 +386,7 @@ vhost_crypto_worker(void *arg)int callfds[VIRTIO_CRYPTO_MAX_NUM_BURST_VQS ];uint32_t lcore_id =rte_lcore_id ();uint32_t burst_size =MAX_PKT_BURST ; +enum rte_crypto_op_type cop_type;uint32_t i, j, k;uint32_t to_fetch, fetched;
@@ -383,9 +394,13 @@ vhost_crypto_worker(void *arg)RTE_LOG (INFO ,USER1 ,"Processing on Core %u started\n" , lcore_id); + cop_type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; +if (options.asymmetric_crypto) + cop_type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; +for (i =0 ; i <NB_VIRTIO_QUEUES ; i++) {if (rte_crypto_op_bulk_alloc (info->cop_pool, -RTE_CRYPTO_OP_TYPE_SYMMETRIC , ops[i], + cop_type, ops[i], burst_size) < burst_size) {RTE_LOG (ERR ,USER1 ,"Failed to alloc cops\n" ); ret =-1 ;
@@ -411,12 +426,11 @@ vhost_crypto_worker(void *arg) fetched);if (unlikely (rte_crypto_op_bulk_alloc ( info->cop_pool, -RTE_CRYPTO_OP_TYPE_SYMMETRIC , + cop_type, ops[j], fetched) < fetched)) {RTE_LOG (ERR ,USER1 ,"Failed realloc\n" );return -1 ; } - fetched = rte_cryptodev_dequeue_burst( info->cid, info->qid, ops_deq[j], RTE_MIN(burst_size,
@@ -477,6 +491,7 @@ main(int argc, char *argv[])struct rte_cryptodev_qp_conf qp_conf;struct rte_cryptodev_config config;struct rte_cryptodev_info dev_info; +enum rte_crypto_op_type cop_type;char name[128 ];uint32_t i, j, lcore;int ret;
@@ -539,12 +554,21 @@ main(int argc, char *argv[]) goto error_exit; } -snprintf (name,127 ,"SESS_POOL_%u" , lo->lcore_id); - info->sess_pool =rte_cryptodev_sym_session_pool_create (name, -SESSION_MAP_ENTRIES , -rte_cryptodev_sym_get_private_session_size ( - info->cid),0 ,0 , -rte_lcore_to_socket_id (lo->lcore_id)); +if (!options.asymmetric_crypto) { +snprintf (name,127 ,"SYM_SESS_POOL_%u" , lo->lcore_id); + info->sess_pool =rte_cryptodev_sym_session_pool_create (name, +SESSION_MAP_ENTRIES , +rte_cryptodev_sym_get_private_session_size ( + info->cid),0 ,0 , +rte_lcore_to_socket_id (lo->lcore_id)); + cop_type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; + }else { +snprintf (name,127 ,"ASYM_SESS_POOL_%u" , lo->lcore_id); + info->sess_pool =rte_cryptodev_asym_session_pool_create (name, +SESSION_MAP_ENTRIES ,0 ,64 , +rte_lcore_to_socket_id (lo->lcore_id)); + cop_type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + }if (!info->sess_pool) {RTE_LOG (ERR ,USER1 ,"Failed to create mempool" );
@@ -553,7 +577,7 @@ main(int argc, char *argv[])snprintf (name,127 ,"COPPOOL_%u" , lo->lcore_id); info->cop_pool =rte_crypto_op_pool_create (name, -RTE_CRYPTO_OP_TYPE_SYMMETRIC ,NB_MEMPOOL_OBJS , + cop_type,NB_MEMPOOL_OBJS ,NB_CACHE_OBJS ,VHOST_CRYPTO_MAX_IV_LEN ,rte_lcore_to_socket_id (lo->lcore_id));
@@ -567,6 +591,8 @@ main(int argc, char *argv[]) qp_conf.nb_descriptors =NB_CRYPTO_DESCRIPTORS ; qp_conf.mp_session = info->sess_pool; +if (options.asymmetric_crypto) + qp_conf.mp_session =NULL ;for (j =0 ; j < dev_info.max_nb_queue_pairs; j++) { ret = rte_cryptodev_queue_pair_setup(info->cid, j,
Signature · 1 line
2.25.1
v4 cover vhost: add RSA support
In reply to Gowrishankar MuthukrishnanThis patch series supports asymmetric RSA in vhost crypto library. It also includes changes to improve vhost crypto library:
* support newer QEMU versions.
* fix broken vhost_crypto example application.
* stabilize crypto fastpath operations.
v4:
- fixed CI issues.
Gowrishankar Muthukrishnan (5):
vhost: skip crypto op fetch before vring init
vhost: update vhost_user crypto session parameters examples/vhost_crypto: fix user callbacks
vhost: support asymmetric RSA crypto ops examples/vhost_crypto: support asymmetric crypto
examples/vhost_crypto/main.c | 54 +++- lib/vhost/vhost_crypto.c | 508 ++++++++++++++++++++++++++++++++--- lib/vhost/vhost_user.h | 33 ++- lib/vhost/virtio_crypto.h | 67 +++++ 4 files changed, 603 insertions(+), 59 deletions(-)
Signature · 1 line
2.25.1
PATCH v4 1/5 vhost: skip crypto op fetch before vring init
Until virtio avail ring is initialized (by VHOST_USER_SET_VRING_ADDR), worker thread should not try to fetch crypto op, which would lead to memory fault.
--- lib/vhost/vhost_crypto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
lib/vhost/vhost_crypto.c +10 -0
@@ -1580,6 +1580,16 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, vq = dev->virtqueue[qid]; +if (unlikely (vq ==NULL )) { +VC_LOG_ERR ("Invalid virtqueue %u" , qid); +return 0 ; + } + +if (unlikely (vq->avail ==NULL )) { +VC_LOG_DBG ("Virtqueue ring not yet initialized %u" , qid); +return 0 ; + } + avail_idx = *((volatile uint16_t *)&vq->avail->idx); start_idx = vq->last_used_idx; count = avail_idx - start_idx;
Signature · 1 line
2.25.1
RE: [v4 1/5] vhost: skip crypto op fetch before vring init
Quoted 10 lines
Subject: [v4 1/5] vhost: skip crypto op fetch before vring init
Until virtio avail ring is initialized (by
VHOST_USER_SET_VRING_ADDR), worker thread should not try to fetch crypto op, which would lead to memory fault.Fixes 939066d96563 ("vhost/crypto: add public function implementation")Signed-off-by Gowrishankar Muthukrishnan <[email protected]>
PATCH v4 2/5 vhost: update vhost_user crypto session parameters
In reply to Gowrishankar MuthukrishnanAs per requirements on vhost_user spec, session id should be located at the end of session parameter.
Update VhostUserCryptoSessionParam structure to support newer QEMU. Due to additional parameters added in QEMU, received payload from QEMU would be larger than existing payload, hence breaks parsing vhost_user message.
This patch addresses both of the above problems.
--- lib/vhost/vhost_crypto.c | 12 ++++++------ lib/vhost/vhost_user.h | 33 +++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-)
lib/vhost/vhost_crypto.c +6 -6
@@ -237,7 +237,7 @@ struct vhost_crypto_data_req {static int transform_cipher_param (struct rte_crypto_sym_xform *xform, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {int ret;
@@ -273,7 +273,7 @@ transform_cipher_param(struct rte_crypto_sym_xform *xform,static int transform_chain_param (struct rte_crypto_sym_xform *xforms, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {struct rte_crypto_sym_xform *xform_cipher, *xform_auth;int ret;
@@ -341,10 +341,10 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto,struct rte_cryptodev_sym_session *session;int ret; -switch (sess_param->op_type) { +switch (sess_param->u.sym_sess.op_type) {case VIRTIO_CRYPTO_SYM_OP_NONE :case VIRTIO_CRYPTO_SYM_OP_CIPHER : - ret =transform_cipher_param (&xform1, sess_param); + ret =transform_cipher_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session msg (%i)" , ret); sess_param->session_id = ret;
@@ -352,7 +352,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, }break ;case VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING : -if (unlikely (sess_param->hash_mode != +if (unlikely (sess_param->u.sym_sess.hash_mode !=VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH )) { sess_param->session_id = -VIRTIO_CRYPTO_NOTSUPP ; VC_LOG_ERR("Error transform session message (%i)",
@@ -362,7 +362,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, xform1.next = &xform2; - ret =transform_chain_param (&xform1, sess_param); + ret =transform_chain_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session message (%i)" , ret); sess_param->session_id = ret;
lib/vhost/vhost_user.h +29 -4
@@ -99,11 +99,10 @@ typedef struct VhostUserLog {/* Comply with Cryptodev-Linux */ #define VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH 512#define VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH 64 +#define VHOST_USER_CRYPTO_MAX_KEY_LENGTH 1024/* Same structure as vhost-user backend session info */ -typedef struct VhostUserCryptoSessionParam { - int64_t session_id; - uint32_t op_code; +typedef struct VhostUserCryptoSymSessionParam { uint32_t cipher_algo; uint32_t cipher_key_len; uint32_t hash_algo;
@@ -114,10 +113,36 @@ typedef struct VhostUserCryptoSessionParam {uint8_t dir;uint8_t hash_mode;uint8_t chaining_dir; -uint8_t *ciphe_key; +uint8_t *cipher_key;uint8_t *auth_key;uint8_t cipher_key_buf[VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH ];uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH ]; +} VhostUserCryptoSymSessionParam; + + +typedef struct VhostUserCryptoAsymRsaParam { +uint32_t padding_algo; +uint32_t hash_algo; +}VhostUserCryptoAsymRsaParam ; + +typedef struct VhostUserCryptoAsymSessionParam { +uint32_t algo; +uint32_t key_type; +uint32_t key_len; +uint8_t *key; +union { +VhostUserCryptoAsymRsaParam rsa; + } u; +uint8_t key_buf[VHOST_USER_CRYPTO_MAX_KEY_LENGTH ]; +}VhostUserCryptoAsymSessionParam ; + +typedef struct VhostUserCryptoSessionParam { +uint32_t op_code; +union { +VhostUserCryptoSymSessionParam sym_sess; +VhostUserCryptoAsymSessionParam asym_sess; + } u; +int64_t session_id; }VhostUserCryptoSessionParam ; typedef struct VhostUserVringArea {
Signature · 1 line
2.25.1
RE: [v4 2/5] vhost: update vhost_user crypto session parameters
Quoted 6 lines
Subject: [v4 2/5] vhost: update
vhost_usercrypto session parametersAs per requirements on
vhost_userspec, session id should be located at the end of session parameter.Update VhostUserCryptoSessionParam structure to support newer QEMU.
Do we need to update QEMU version in documentation somewhere?
Quoted 7 lines
Due to additional parameters added in QEMU, received payload from QEMU would be larger than existing payload, hence breaks parsing
vhost_usermessage.This patch addresses both of the above problems.
Signed-off-by Gowrishankar Muthukrishnan <[email protected]>
PATCH v4 3/5 examples/vhost_crypto: fix user callbacks
In reply to Gowrishankar MuthukrishnanIn order to handle new vhost user connection, use new_connection and destroy_connection callbacks.
--- examples/vhost_crypto/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
examples/vhost_crypto/main.c +2 -2
@@ -362,8 +362,8 @@ destroy_device(int vid) }static const struct rte_vhost_device_ops virtio_crypto_device_ops = { - .new_device = new_device, - .destroy_device = destroy_device, + .new_connection = new_device, + .destroy_connection = destroy_device, }; static int
Signature · 1 line
2.25.1
RE: [v4 3/5] examples/vhost_crypto: fix user callbacks
Quoted 9 lines
Subject: [v4 3/5] examples/vhost_crypto: fix user callbacks
In order to handle new vhost user connection, use
new_connectionanddestroy_connectioncallbacks.Fixes f5188211c721 ("examples/vhost_crypto: add sample application")Signed-off-by Gowrishankar Muthukrishnan <[email protected]>
PATCH v4 4/5 vhost: support asymmetric RSA crypto ops
In reply to Gowrishankar MuthukrishnanSupport asymmetric RSA crypto operations in vhost-user.
---
v4:
- fixed CI issue.
--- lib/vhost/vhost_crypto.c | 486 +++++++++++++++++++++++++++++++++++--- lib/vhost/virtio_crypto.h | 67 ++++++ 2 files changed, 518 insertions(+), 35 deletions(-)
lib/vhost/vhost_crypto.c +451 -35
@@ -54,6 +54,14 @@ RTE_LOG_REGISTER_SUFFIX(vhost_crypto_logtype, crypto, INFO);*/ #define vhost_crypto_desc vring_desc +struct vhost_crypto_session { +union { +struct rte_cryptodev_asym_session *asym; +struct rte_cryptodev_sym_session *sym; + }; +enum rte_crypto_op_type type; +}; +static int cipher_algo_transform (uint32_t virtio_cipher_algo,enum rte_crypto_cipher_algorithm *algo)
@@ -206,8 +214,10 @@ struct __rte_cache_aligned vhost_crypto {uint64_t last_session_id; -uint64_t cache_session_id; -struct rte_cryptodev_sym_session *cache_session; +uint64_t cache_sym_session_id; +struct rte_cryptodev_sym_session *cache_sym_session; +uint64_t cache_asym_session_id; +struct rte_cryptodev_asym_session *cache_asym_session;/** socket id for the device */ int socket_id;
@@ -334,10 +344,11 @@ transform_chain_param(struct rte_crypto_sym_xform *xforms, }static void -vhost_crypto_create_sess (struct vhost_crypto *vcrypto, +vhost_crypto_create_sym_sess (struct vhost_crypto *vcrypto,VhostUserCryptoSessionParam *sess_param) {struct rte_crypto_sym_xform xform1 = {0 }, xform2 = {0 }; +struct vhost_crypto_session *vhost_session;struct rte_cryptodev_sym_session *session;int ret;
@@ -384,42 +395,277 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto,return ; } -/* insert hash to map */ -if (rte_hash_add_key_data (vcrypto->session_map, - &vcrypto->last_session_id, session) <0 ) { + vhost_session =rte_zmalloc (NULL ,sizeof (*vhost_session),0 ); +if (vhost_session ==NULL ) { +VC_LOG_ERR ("Failed to alloc session memory" ); + goto error_exit; + } + + vhost_session->type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; + vhost_session->sym = session; + +/* insert session to map */ +if ((rte_hash_add_key_data (vcrypto->session_map, + &vcrypto->last_session_id, vhost_session) <0 )) {VC_LOG_ERR ("Failed to insert session to hash table" ); + goto error_exit; + } + +VC_LOG_INFO ("Session %" PRIu64" created for vdev %i." , + vcrypto->last_session_id, vcrypto->dev->vid); + + sess_param->session_id = vcrypto->last_session_id; + vcrypto->last_session_id++; +return ; + +error_exit: +if (rte_cryptodev_sym_session_free (vcrypto->cid, session) <0 ) +VC_LOG_ERR ("Failed to free session" ); + + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +rte_free (vhost_session); +} + +static int +tlv_decode (uint8_t *tlv,uint8_t type,uint8_t **data,size_t *data_len) +{ +size_t tlen = -EINVAL , len; + +if (tlv[0 ] != type) +return -EINVAL ; -if (rte_cryptodev_sym_session_free (vcrypto->cid, session) <0 ) -VC_LOG_ERR ("Failed to free session" ); +if (tlv[1 ] ==0x82 ) { + len = (tlv[2 ] <<8 ) | tlv[3 ]; + *data = &tlv[4 ]; + tlen = len +4 ; + }else if (tlv[1 ] ==0x81 ) { + len = tlv[2 ]; + *data = &tlv[3 ]; + tlen = len +3 ; + }else { + len = tlv[1 ]; + *data = &tlv[2 ]; + tlen = len +2 ; + } + + *data_len = len; +return tlen; +} + +static int +virtio_crypto_asym_rsa_der_to_xform (uint8_t *der,size_t der_len, +struct rte_crypto_asym_xform *xform) +{ +uint8_t *n =NULL , *e =NULL , *d =NULL , *p =NULL , *q =NULL , *dp =NULL , + *dq =NULL , *qinv =NULL , *v =NULL , *tlv; +size_t nlen, elen, dlen, plen, qlen, dplen, dqlen, qinvlen, vlen; +int len; + +RTE_SET_USED (der_len); + +if (der[0 ] !=0x30 ) +return -EINVAL ; + +if (der[1 ] ==0x82 ) + tlv = &der[4 ]; +else if (der[1 ] ==0x81 ) + tlv = &der[3 ]; +else +return -EINVAL ; + + len =tlv_decode (tlv,0x02 , &v, &vlen); +if (len <0 || v[0 ] !=0x0 || vlen !=1 ) +return -EINVAL ; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &n, &nlen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &e, &elen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &d, &dlen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &p, &plen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &q, &qlen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &dp, &dplen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &dq, &dqlen); +if (len <0 ) +return len; + + tlv = tlv + len; + len =tlv_decode (tlv,0x02 , &qinv, &qinvlen); +if (len <0 ) +return len; + + xform->rsa.n.data = n; + xform->rsa.n.length = nlen; + xform->rsa.e.data = e; + xform->rsa.e.length = elen; + xform->rsa.d.data = d; + xform->rsa.d.length = dlen; + xform->rsa.qt.p.data = p; + xform->rsa.qt.p.length = plen; + xform->rsa.qt.q.data = q; + xform->rsa.qt.q.length = qlen; + xform->rsa.qt.dP.data = dp; + xform->rsa.qt.dP.length = dplen; + xform->rsa.qt.dQ.data = dq; + xform->rsa.qt.dQ.length = dqlen; + xform->rsa.qt.qInv.data = qinv; + xform->rsa.qt.qInv.length = qinvlen; + +RTE_ASSERT ((tlv + len - &der[0 ]) == der_len); +return 0 ; +} + +static int +rsa_param_transform (struct rte_crypto_asym_xform *xform, +VhostUserCryptoAsymSessionParam *param) +{ +int ret; + + ret =virtio_crypto_asym_rsa_der_to_xform (param->key_buf, param->key_len, xform); +if (ret <0 ) +return ret; + +switch (param->u.rsa.padding_algo) { +case VIRTIO_CRYPTO_RSA_RAW_PADDING : + xform->rsa.padding.type =RTE_CRYPTO_RSA_PADDING_NONE ; +break ; +case VIRTIO_CRYPTO_RSA_PKCS1_PADDING : + xform->rsa.padding.type =RTE_CRYPTO_RSA_PADDING_PKCS1_5 ; +break ; +default : +VC_LOG_ERR ("Unknown padding type" ); +return -EINVAL ; + } + + xform->rsa.key_type =RTE_RSA_KEY_TYPE_QT ; + xform->xform_type =RTE_CRYPTO_ASYM_XFORM_RSA ; +return 0 ; +} + +static void +vhost_crypto_create_asym_sess (struct vhost_crypto *vcrypto, +VhostUserCryptoSessionParam *sess_param) +{ +struct rte_cryptodev_asym_session *session =NULL ; +struct vhost_crypto_session *vhost_session; +struct rte_crypto_asym_xform xform = {0 }; +int ret; + +switch (sess_param->u.asym_sess.algo) { +case VIRTIO_CRYPTO_AKCIPHER_RSA : + ret =rsa_param_transform (&xform, &sess_param->u.asym_sess); +if (unlikely (ret <0 )) { +VC_LOG_ERR ("Error transform session msg (%i)" , ret); + sess_param->session_id = ret; +return ; + } +break ; +default : +VC_LOG_ERR ("Invalid op algo" ); sess_param->session_id = -VIRTIO_CRYPTO_ERR ;return ; } + ret =rte_cryptodev_asym_session_create (vcrypto->cid, &xform, + vcrypto->sess_pool, (void *)&session); +if (session ==NULL ) { +VC_LOG_ERR ("Failed to create session" ); + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +return ; + } + + vhost_session =rte_zmalloc (NULL ,sizeof (*vhost_session),0 ); +if (vhost_session ==NULL ) { +VC_LOG_ERR ("Failed to alloc session memory" ); + goto error_exit; + } + + vhost_session->type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + vhost_session->asym = session; + +/* insert session to map */ +if ((rte_hash_add_key_data (vcrypto->session_map, + &vcrypto->last_session_id, vhost_session) <0 )) { +VC_LOG_ERR ("Failed to insert session to hash table" ); + goto error_exit; + } +VC_LOG_INFO ("Session %" PRIu64" created for vdev %i." , vcrypto->last_session_id, vcrypto->dev->vid); sess_param->session_id = vcrypto->last_session_id; vcrypto->last_session_id++; +return ; + +error_exit: +if (rte_cryptodev_asym_session_free (vcrypto->cid, session) <0 ) +VC_LOG_ERR ("Failed to free session" ); + sess_param->session_id = -VIRTIO_CRYPTO_ERR ; +rte_free (vhost_session); +} + +static void +vhost_crypto_create_sess (struct vhost_crypto *vcrypto, +VhostUserCryptoSessionParam *sess_param) +{ +if (sess_param->op_code ==VIRTIO_CRYPTO_AKCIPHER_CREATE_SESSION ) +vhost_crypto_create_asym_sess (vcrypto, sess_param); +else +vhost_crypto_create_sym_sess (vcrypto, sess_param); }static int vhost_crypto_close_sess (struct vhost_crypto *vcrypto,uint64_t session_id) { -struct rte_cryptodev_sym_session *session; +struct vhost_crypto_session *vhost_session =NULL ;uint64_t sess_id = session_id;int ret; ret =rte_hash_lookup_data (vcrypto->session_map, &sess_id, - (void **)&session); - + (void **)&vhost_session);if (unlikely (ret <0 )) { -VC_LOG_ERR ("Failed to delete session %" PRIu64"." , session_id); +VC_LOG_ERR ("Failed to find session for id %" PRIu64"." , session_id);return -VIRTIO_CRYPTO_INVSESS ; } -if (rte_cryptodev_sym_session_free (vcrypto->cid, session) <0 ) { -VC_LOG_DBG ("Failed to free session" ); -return -VIRTIO_CRYPTO_ERR ; +if (vhost_session->type ==RTE_CRYPTO_OP_TYPE_SYMMETRIC ) { +if (rte_cryptodev_sym_session_free (vcrypto->cid, + vhost_session->sym) <0 ) { +VC_LOG_DBG ("Failed to free session" ); +return -VIRTIO_CRYPTO_ERR ; + } + }else if (vhost_session->type ==RTE_CRYPTO_OP_TYPE_ASYMMETRIC ) { +if (rte_cryptodev_asym_session_free (vcrypto->cid, + vhost_session->asym) <0 ) { +VC_LOG_DBG ("Failed to free session" ); +return -VIRTIO_CRYPTO_ERR ; + } + }else { +VC_LOG_ERR ("Invalid session for id %" PRIu64"." , session_id); +return -VIRTIO_CRYPTO_INVSESS ; }if (rte_hash_del_key (vcrypto->session_map, &sess_id) <0 ) {
@@ -430,6 +676,7 @@ vhost_crypto_close_sess(struct vhost_crypto *vcrypto, uint64_t session_id)VC_LOG_INFO ("Session %" PRIu64" deleted for vdev %i." , sess_id, vcrypto->dev->vid); +rte_free (vhost_session);return 0 ; }
@@ -1123,6 +1370,109 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,return ret; } +static __rte_always_inline uint8_t +prepare_asym_rsa_op (struct vhost_crypto *vcrypto,struct rte_crypto_op *op, +struct vhost_crypto_data_req *vc_req, +struct virtio_crypto_op_data_req *req, +struct vhost_crypto_desc *head, +uint32_t max_n_descs) + __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) +{ +struct rte_crypto_rsa_op_param *rsa = &op->asym->rsa; +struct vhost_crypto_desc *desc = head; +uint8_t ret =VIRTIO_CRYPTO_ERR ; +uint16_t wlen =0 ; + +/* prepare */ +switch (vcrypto->option) { +case RTE_VHOST_CRYPTO_ZERO_COPY_DISABLE : + vc_req->wb_pool = vcrypto->wb_pool; +if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_SIGN ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_SIGN ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.src_data_len; + rsa->sign.length = req->u.akcipher_req.para.dst_data_len; + wlen = rsa->sign.length; + desc =find_write_desc (head, desc, max_n_descs); +if (unlikely (!desc)) { +VC_LOG_ERR ("Cannot find write location" ); + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + rsa->sign.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RW ); +if (unlikely (rsa->sign.data ==NULL )) { + ret =VIRTIO_CRYPTO_ERR ; + goto error_exit; + } + + desc +=1 ; + }else if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_VERIFY ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_VERIFY ; + rsa->sign.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->sign.length = req->u.akcipher_req.para.src_data_len; + desc +=1 ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.dst_data_len; + desc +=1 ; + }else if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_ENCRYPT ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_ENCRYPT ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.src_data_len; + rsa->cipher.length = req->u.akcipher_req.para.dst_data_len; + wlen = rsa->cipher.length; + desc =find_write_desc (head, desc, max_n_descs); +if (unlikely (!desc)) { +VC_LOG_ERR ("Cannot find write location" ); + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + rsa->cipher.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RW ); +if (unlikely (rsa->cipher.data ==NULL )) { + ret =VIRTIO_CRYPTO_ERR ; + goto error_exit; + } + + desc +=1 ; + }else if (req->header.opcode ==VIRTIO_CRYPTO_AKCIPHER_DECRYPT ) { + rsa->op_type =RTE_CRYPTO_ASYM_OP_DECRYPT ; + rsa->cipher.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->cipher.length = req->u.akcipher_req.para.src_data_len; + desc +=1 ; + rsa->message.data =get_data_ptr (vc_req, desc,VHOST_ACCESS_RO ); + rsa->message.length = req->u.akcipher_req.para.dst_data_len; + desc +=1 ; + }else { + goto error_exit; + } +break ; +case RTE_VHOST_CRYPTO_ZERO_COPY_ENABLE : +default : + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + op->type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + op->sess_type =RTE_CRYPTO_OP_WITH_SESSION ; + + vc_req->inhdr =get_data_ptr (vc_req, desc,VHOST_ACCESS_WO ); +if (unlikely (vc_req->inhdr ==NULL )) { + ret =VIRTIO_CRYPTO_BADMSG ; + goto error_exit; + } + + vc_req->inhdr->status =VIRTIO_CRYPTO_OK ; + vc_req->len = wlen +INHDR_LEN ; +return 0 ; +error_exit: +if (vc_req->wb) +free_wb_data (vc_req->wb, vc_req->wb_pool); + + vc_req->len =INHDR_LEN ; +return ret; +} +/** * Process on descriptor */
@@ -1133,17 +1483,21 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, uint16_t desc_idx) __rte_no_thread_safety_analysis/* FIXME: requires iotlb_lock? */ { -struct vhost_crypto_data_req *vc_req =rte_mbuf_to_priv (op->sym->m_src); -struct rte_cryptodev_sym_session *session; +struct vhost_crypto_data_req *vc_req, *vc_req_out; +struct rte_cryptodev_asym_session *asym_session; +struct rte_cryptodev_sym_session *sym_session; +struct vhost_crypto_session *vhost_session; +struct vhost_crypto_desc *desc = descs; +uint32_t nb_descs =0 , max_n_descs, i; +struct vhost_crypto_data_req data_req;struct virtio_crypto_op_data_req req;struct virtio_crypto_inhdr *inhdr; -struct vhost_crypto_desc *desc = descs;struct vring_desc *src_desc;uint64_t session_id;uint64_t dlen; -uint32_t nb_descs =0 , max_n_descs, i;int err; + vc_req = &data_req; vc_req->desc_idx = desc_idx; vc_req->dev = vcrypto->dev; vc_req->vq = vq;
@@ -1226,12 +1580,14 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto,switch (req.header.opcode) {case VIRTIO_CRYPTO_CIPHER_ENCRYPT :case VIRTIO_CRYPTO_CIPHER_DECRYPT : + vc_req_out =rte_mbuf_to_priv (op->sym->m_src); +memcpy (vc_req_out, vc_req,sizeof (struct vhost_crypto_data_req )); session_id = req.header.session_id;/* one branch to avoid unnecessary table lookup */ -if (vcrypto->cache_session_id != session_id) { +if (vcrypto->cache_sym_session_id != session_id) { err =rte_hash_lookup_data (vcrypto->session_map, - &session_id, (void **)&session); + &session_id, (void **)&vhost_session);if (unlikely (err <0 )) { err =VIRTIO_CRYPTO_ERR ; VC_LOG_ERR("Failed to find session %"PRIu64,
@@ -1239,13 +1595,14 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, goto error_exit; } - vcrypto->cache_session = session; - vcrypto->cache_session_id = session_id; + vcrypto->cache_sym_session = vhost_session->sym; + vcrypto->cache_sym_session_id = session_id; } - session = vcrypto->cache_session; + sym_session = vcrypto->cache_sym_session; + op->type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; - err =rte_crypto_op_attach_sym_session (op, session); + err =rte_crypto_op_attach_sym_session (op, sym_session);if (unlikely (err <0 )) { err =VIRTIO_CRYPTO_ERR ;VC_LOG_ERR ("Failed to attach session to op" );
@@ -1257,12 +1614,12 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, err =VIRTIO_CRYPTO_NOTSUPP ;break ;case VIRTIO_CRYPTO_SYM_OP_CIPHER : - err =prepare_sym_cipher_op (vcrypto, op, vc_req, + err =prepare_sym_cipher_op (vcrypto, op, vc_req_out, &req.u.sym_req.u.cipher, desc, max_n_descs);break ;case VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING : - err =prepare_sym_chain_op (vcrypto, op, vc_req, + err =prepare_sym_chain_op (vcrypto, op, vc_req_out, &req.u.sym_req.u.chain, desc, max_n_descs);break ;
@@ -1271,6 +1628,53 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto,VC_LOG_ERR ("Failed to process sym request" ); goto error_exit; } +break ; +case VIRTIO_CRYPTO_AKCIPHER_SIGN : +case VIRTIO_CRYPTO_AKCIPHER_VERIFY : +case VIRTIO_CRYPTO_AKCIPHER_ENCRYPT : +case VIRTIO_CRYPTO_AKCIPHER_DECRYPT : + session_id = req.header.session_id; + +/* one branch to avoid unnecessary table lookup */ +if (vcrypto->cache_asym_session_id != session_id) { + err =rte_hash_lookup_data (vcrypto->session_map, + &session_id, (void **)&vhost_session); +if (unlikely (err <0 )) { + err =VIRTIO_CRYPTO_ERR ; +VC_LOG_ERR ("Failed to find asym session %" PRIu64, + session_id); + goto error_exit; + } + + vcrypto->cache_asym_session = vhost_session->asym; + vcrypto->cache_asym_session_id = session_id; + } + + asym_session = vcrypto->cache_asym_session; + op->type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + + err =rte_crypto_op_attach_asym_session (op, asym_session); +if (unlikely (err <0 )) { + err =VIRTIO_CRYPTO_ERR ; +VC_LOG_ERR ("Failed to attach asym session to op" ); + goto error_exit; + } + + vc_req_out =rte_cryptodev_asym_session_get_user_data (asym_session); +rte_memcpy (vc_req_out, vc_req,sizeof (struct vhost_crypto_data_req )); + vc_req_out->wb =NULL ; + +switch (req.header.algo) { +case VIRTIO_CRYPTO_AKCIPHER_RSA : + err =prepare_asym_rsa_op (vcrypto, op, vc_req_out, + &req, desc, max_n_descs); +break ; + } +if (unlikely (err !=0 )) { +VC_LOG_ERR ("Failed to process asym request" ); + goto error_exit; + } +break ;default : err =VIRTIO_CRYPTO_ERR ;
@@ -1294,12 +1698,22 @@ static __rte_always_inline struct vhost_virtqueue * vhost_crypto_finalize_one_request(struct rte_crypto_op *op, struct vhost_virtqueue *old_vq) { - struct rte_mbuf *m_src = op->sym->m_src; -struct rte_mbuf *m_dst = op->sym->m_dst; -struct vhost_crypto_data_req *vc_req =rte_mbuf_to_priv (m_src); + struct rte_mbuf *m_src = NULL, *m_dst = NULL; +struct vhost_crypto_data_req *vc_req;struct vhost_virtqueue *vq;uint16_t used_idx, desc_idx; +if (op->type ==RTE_CRYPTO_OP_TYPE_SYMMETRIC ) { + m_src = op->sym->m_src; + m_dst = op->sym->m_dst; + vc_req =rte_mbuf_to_priv (m_src); + }else if (op->type ==RTE_CRYPTO_OP_TYPE_ASYMMETRIC ) { + vc_req =rte_cryptodev_asym_session_get_user_data (op->asym->session); + }else { +VC_LOG_ERR ("Invalid crypto op type" ); +return NULL ; + } +if (unlikely (!vc_req)) {VC_LOG_ERR ("Failed to retrieve vc_req" );return NULL ;
@@ -1321,10 +1735,11 @@ vhost_crypto_finalize_one_request(struct rte_crypto_op *op, vq->used->ring[desc_idx].id = vq->avail->ring[desc_idx]; vq->used->ring[desc_idx].len = vc_req->len; -rte_mempool_put (m_src->pool, (void *)m_src); - -if (m_dst) -rte_mempool_put (m_dst->pool, (void *)m_dst); +if (op->type ==RTE_CRYPTO_OP_TYPE_SYMMETRIC ) { +rte_mempool_put (m_src->pool, (void *)m_src); +if (m_dst) +rte_mempool_put (m_dst->pool, (void *)m_dst); + }return vc_req->vq; }
@@ -1407,7 +1822,8 @@ rte_vhost_crypto_create(int vid, uint8_t cryptodev_id, vcrypto->sess_pool = sess_pool; vcrypto->cid = cryptodev_id; - vcrypto->cache_session_id =UINT64_MAX ; + vcrypto->cache_sym_session_id =UINT64_MAX ; + vcrypto->cache_asym_session_id =UINT64_MAX ; vcrypto->last_session_id =1 ; vcrypto->dev = dev; vcrypto->option =RTE_VHOST_CRYPTO_ZERO_COPY_DISABLE ;
lib/vhost/virtio_crypto.h +67 -0
115 lines not on this page · raw message
Signature · 1 line
2.25.1
RE: [v4 4/5] vhost: support asymmetric RSA crypto ops
Quoted 5 lines
Subject: [v4 4/5] vhost: support asymmetric RSA crypto ops
Support asymmetric RSA crypto operations in vhost-user.
Signed-off-by Gowrishankar Muthukrishnan <[email protected]>
You may want to update documentation and release notes also.
PATCH v4 5/5 examples/vhost_crypto: support asymmetric crypto
In reply to Gowrishankar MuthukrishnanSupport asymmetric crypto operations.
--- examples/vhost_crypto/main.c | 50 +++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-)
examples/vhost_crypto/main.c +38 -12
@@ -59,6 +59,7 @@ struct vhost_crypto_options {uint32_t nb_los;uint32_t zero_copy;uint32_t guest_polling; +bool asymmetric_crypto; } options;enum {
@@ -70,6 +71,8 @@ enum {OPT_ZERO_COPY_NUM , #define OPT_POLLING "guest-polling"OPT_POLLING_NUM , +#define OPT_ASYM "asymmetric-crypto" + OPT_ASYM_NUM, };#define NB_SOCKET_FIELDS (2)
@@ -202,9 +205,10 @@ vhost_crypto_usage(const char *prgname)" --%s <lcore>,SOCKET-FILE-PATH\n" " --%s (lcore,cdev_id,queue_id)[,(lcore,cdev_id,queue_id)]\n" " --%s: zero copy\n" -" --%s: guest polling\n" , +" --%s: guest polling\n" +" --%s: asymmetric crypto\n" , prgname,OPT_SOCKET_FILE ,OPT_CONFIG , - OPT_ZERO_COPY, OPT_POLLING); + OPT_ZERO_COPY, OPT_POLLING, OPT_ASYM); } static int
@@ -223,6 +227,8 @@ vhost_crypto_parse_args(int argc, char **argv) NULL, OPT_ZERO_COPY_NUM}, {OPT_POLLING , no_argument, NULL, OPT_POLLING_NUM}, + {OPT_ASYM, no_argument, + NULL, OPT_ASYM_NUM}, {NULL, 0, 0, 0} };
@@ -262,6 +268,10 @@ vhost_crypto_parse_args(int argc, char **argv) options.guest_polling =1 ;break ; +case OPT_ASYM_NUM : + options.asymmetric_crypto = true; +break ; +default :vhost_crypto_usage (prgname);return -EINVAL ;
@@ -376,6 +386,7 @@ vhost_crypto_worker(void *arg)int callfds[VIRTIO_CRYPTO_MAX_NUM_BURST_VQS ];uint32_t lcore_id =rte_lcore_id ();uint32_t burst_size =MAX_PKT_BURST ; +enum rte_crypto_op_type cop_type;uint32_t i, j, k;uint32_t to_fetch, fetched;
@@ -383,9 +394,13 @@ vhost_crypto_worker(void *arg)RTE_LOG (INFO ,USER1 ,"Processing on Core %u started\n" , lcore_id); + cop_type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; +if (options.asymmetric_crypto) + cop_type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; +for (i =0 ; i <NB_VIRTIO_QUEUES ; i++) {if (rte_crypto_op_bulk_alloc (info->cop_pool, -RTE_CRYPTO_OP_TYPE_SYMMETRIC , ops[i], + cop_type, ops[i], burst_size) < burst_size) {RTE_LOG (ERR ,USER1 ,"Failed to alloc cops\n" ); ret =-1 ;
@@ -411,12 +426,11 @@ vhost_crypto_worker(void *arg) fetched);if (unlikely (rte_crypto_op_bulk_alloc ( info->cop_pool, -RTE_CRYPTO_OP_TYPE_SYMMETRIC , + cop_type, ops[j], fetched) < fetched)) {RTE_LOG (ERR ,USER1 ,"Failed realloc\n" );return -1 ; } - fetched = rte_cryptodev_dequeue_burst( info->cid, info->qid, ops_deq[j], RTE_MIN(burst_size,
@@ -477,6 +491,7 @@ main(int argc, char *argv[])struct rte_cryptodev_qp_conf qp_conf;struct rte_cryptodev_config config;struct rte_cryptodev_info dev_info; +enum rte_crypto_op_type cop_type;char name[128 ];uint32_t i, j, lcore;int ret;
@@ -539,12 +554,21 @@ main(int argc, char *argv[]) goto error_exit; } -snprintf (name,127 ,"SESS_POOL_%u" , lo->lcore_id); - info->sess_pool =rte_cryptodev_sym_session_pool_create (name, -SESSION_MAP_ENTRIES , -rte_cryptodev_sym_get_private_session_size ( - info->cid),0 ,0 , -rte_lcore_to_socket_id (lo->lcore_id)); +if (!options.asymmetric_crypto) { +snprintf (name,127 ,"SYM_SESS_POOL_%u" , lo->lcore_id); + info->sess_pool =rte_cryptodev_sym_session_pool_create (name, +SESSION_MAP_ENTRIES , +rte_cryptodev_sym_get_private_session_size ( + info->cid),0 ,0 , +rte_lcore_to_socket_id (lo->lcore_id)); + cop_type =RTE_CRYPTO_OP_TYPE_SYMMETRIC ; + }else { +snprintf (name,127 ,"ASYM_SESS_POOL_%u" , lo->lcore_id); + info->sess_pool =rte_cryptodev_asym_session_pool_create (name, +SESSION_MAP_ENTRIES ,0 ,64 , +rte_lcore_to_socket_id (lo->lcore_id)); + cop_type =RTE_CRYPTO_OP_TYPE_ASYMMETRIC ; + }if (!info->sess_pool) {RTE_LOG (ERR ,USER1 ,"Failed to create mempool" );
@@ -553,7 +577,7 @@ main(int argc, char *argv[])snprintf (name,127 ,"COPPOOL_%u" , lo->lcore_id); info->cop_pool =rte_crypto_op_pool_create (name, -RTE_CRYPTO_OP_TYPE_SYMMETRIC ,NB_MEMPOOL_OBJS , + cop_type,NB_MEMPOOL_OBJS ,NB_CACHE_OBJS ,VHOST_CRYPTO_MAX_IV_LEN ,rte_lcore_to_socket_id (lo->lcore_id));
@@ -567,6 +591,8 @@ main(int argc, char *argv[]) qp_conf.nb_descriptors =NB_CRYPTO_DESCRIPTORS ; qp_conf.mp_session = info->sess_pool; +if (options.asymmetric_crypto) + qp_conf.mp_session =NULL ;for (j =0 ; j < dev_info.max_nb_queue_pairs; j++) { ret = rte_cryptodev_queue_pair_setup(info->cid, j,
Signature · 1 line
2.25.1
RE: [v4 5/5] examples/vhost_crypto: support asymmetric crypto
Quoted 6 lines
Subject: [v4 5/5] examples/vhost_crypto: support asymmetric crypto
Support asymmetric crypto operations.
Signed-off-by Gowrishankar Muthukrishnan <[email protected]>---
Update documentation for newly added parameter.
Apart from that.
RE: [v4 0/5] vhost: add RSA support
In reply to Gowrishankar MuthukrishnanHi Maxime,
Can you pick these patches in vhost tree first so that virtio/crypto patches can be merged in crypto tree?
Regards,
Akhil
Quoted 26 lines
Subject: [v4 0/5] vhost: add RSA support
This patch series supports asymmetric RSA in vhost crypto library. It also includes changes to improve vhost crypto library:
* support newer QEMU versions.
* fix brokenvhost_cryptoexample application.
* stabilize crypto fastpath operations.v4:
- fixed CI issues.Gowrishankar Muthukrishnan (5):
vhost: skip crypto op fetch before vring init
vhost: updatevhost_usercrypto session parameters examples/vhost_crypto: fix user callbacks
vhost: support asymmetric RSA crypto ops examples/vhost_crypto: support asymmetric cryptoexamples/vhost_crypto/main.c | 54 +++- lib/vhost/vhost_crypto.c | 508 ++++++++++++++++++++++++++++++++--- lib/vhost/vhost_user.h | 33 ++- lib/vhost/virtio_crypto.h | 67 +++++ 4 files changed, 603 insertions(+), 59 deletions(-)--
2.25.1
v5 cover vhost: add RSA support
In reply to Gowrishankar MuthukrishnanThis patch series supports asymmetric RSA in vhost crypto library. It also includes changes to improve vhost crypto library:
* support newer QEMU versions.
* fix broken vhost_crypto example application.
* stabilize crypto fastpath operations.
v5:
- added docs.
Gowrishankar Muthukrishnan (5):
vhost: skip crypto op fetch before vring init
vhost: update vhost_user crypto session parameters examples/vhost_crypto: fix user callbacks
vhost: support asymmetric RSA crypto ops examples/vhost_crypto: support asymmetric crypto
doc/guides/rel_notes/release_25_03.rst | 3 + doc/guides/sample_app_ug/vhost_crypto.rst | 5 + examples/vhost_crypto/main.c | 54 ++- lib/vhost/vhost_crypto.c | 508 ++++++++++++++++++++-- lib/vhost/vhost_user.h | 33 +- lib/vhost/virtio_crypto.h | 67 +++ 6 files changed, 611 insertions(+), 59 deletions(-)
Signature · 1 line
2.25.1
PATCH v5 1/5 vhost: skip crypto op fetch before vring init
Until virtio avail ring is initialized (by VHOST_USER_SET_VRING_ADDR), worker thread should not try to fetch crypto op, which would lead to memory fault.
--- lib/vhost/vhost_crypto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
lib/vhost/vhost_crypto.c +10 -0
@@ -1580,6 +1580,16 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, vq = dev->virtqueue[qid]; +if (unlikely (vq ==NULL )) { +VC_LOG_ERR ("Invalid virtqueue %u" , qid); +return 0 ; + } + +if (unlikely (vq->avail ==NULL )) { +VC_LOG_DBG ("Virtqueue ring not yet initialized %u" , qid); +return 0 ; + } + avail_idx = *((volatile uint16_t *)&vq->avail->idx); start_idx = vq->last_used_idx; count = avail_idx - start_idx;
Signature · 1 line
2.25.1
Re: [v5 1/5] vhost: skip crypto op fetch before vring init
Quoted 21 lines · Gowrishankar Muthukrishnan
Until virtio avail ring is initialized (by
VHOST_USER_SET_VRING_ADDR), worker thread should not try to fetch crypto op, which would lead to memory fault.Fixes 939066d96563 ("vhost/crypto: add public function implementation")Signed-off-by Gowrishankar Muthukrishnan <[email protected]>Acked-by Akhil Goyal <[email protected]>--- lib/vhost/vhost_crypto.c | 10 ++++++++++ 1 file changed, 10 insertions(+)lib/vhost/vhost_crypto.c +0
-0@@ -1580,6 +1580,16 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, vq = dev->virtqueue[qid];
lib/vhost/vhost_crypto.c rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, · line 1592
Quoted 10 lines
lib/vhost/vhost_crypto.c +10
-0+if (unlikely (vq ==NULL )) { +VC_LOG_ERR ("Invalid virtqueue %u" , qid); +return 0 ; + } + +if (unlikely (vq->avail ==NULL )) { +VC_LOG_DBG ("Virtqueue ring not yet initialized %u" , qid); +return 0 ; + } +
I think the proper fix to:
1. acquire the access_lock as reader
2. check whether vq is enabled
3. acquire the iotlb lock as a reader
4. check vq's access_ok
You can have a look at rte_vhost_dequeue_burst for example.
Quoted 3 lines
lib/vhost/vhost_crypto.c +0
-0avail_idx = *((volatile uint16_t *)&vq->avail->idx); start_idx = vq->last_used_idx; count = avail_idx - start_idx;
RE: [EXTERNAL] Re: [v5 1/5] vhost: skip crypto op fetch before vring init
Hi Maxime,
Quoted 18 lines
lib/vhost/vhost_crypto.c rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, · line 1592
Quoted 11 lines
lib/vhost/vhost_crypto.c +10
-0+if (unlikely (vq ==NULL )) { +VC_LOG_ERR ("Invalid virtqueue %u" , qid); +return 0 ; + } + +if (unlikely (vq->avail ==NULL )) { +VC_LOG_DBG ("Virtqueue ring not yet initialized %u" , qid); +return 0 ; + } +I think the proper fix to:
1. acquire theaccess_lockas reader
2. check whether vq is enabled
3. acquire the iotlb lock as a reader
4. check vq'saccess_ok
Ack. Except for vq->enabled, next version of this patch would carry these checks. Current virtio crypto for vhost_user does not request SET_VRING_ENABLE, so this flag would not be set.
Thanks,
Gowrishankar
Quoted 5 lines
You can have a look at
rte_vhost_dequeue_burstfor example.Quoted 3 lines
avail_idx = *((volatile uint16_t *)&vq->avail->idx); start_idx = vq->last_used_idx; count = avail_idx - start_idx;
PATCH v5 2/5 vhost: update vhost_user crypto session parameters
In reply to Gowrishankar MuthukrishnanAs per requirements on vhost_user spec, session id should be located at the end of session parameter.
Update VhostUserCryptoSessionParam structure to support newer QEMU versions (v9). Due to additional parameters added in QEMU, received payload from QEMU would be larger than existing payload. Hence, it would break parsing vhost_user messages.
This patch addresses both of the above problems.
---
v5:
- updated patch description for QEMU version.
--- lib/vhost/vhost_crypto.c | 12 ++++++------ lib/vhost/vhost_user.h | 33 +++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-)
lib/vhost/vhost_crypto.c +6 -6
@@ -237,7 +237,7 @@ struct vhost_crypto_data_req {static int transform_cipher_param (struct rte_crypto_sym_xform *xform, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {int ret;
@@ -273,7 +273,7 @@ transform_cipher_param(struct rte_crypto_sym_xform *xform,static int transform_chain_param (struct rte_crypto_sym_xform *xforms, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {struct rte_crypto_sym_xform *xform_cipher, *xform_auth;int ret;
@@ -341,10 +341,10 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto,struct rte_cryptodev_sym_session *session;int ret; -switch (sess_param->op_type) { +switch (sess_param->u.sym_sess.op_type) {case VIRTIO_CRYPTO_SYM_OP_NONE :case VIRTIO_CRYPTO_SYM_OP_CIPHER : - ret =transform_cipher_param (&xform1, sess_param); + ret =transform_cipher_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session msg (%i)" , ret); sess_param->session_id = ret;
@@ -352,7 +352,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, }break ;case VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING : -if (unlikely (sess_param->hash_mode != +if (unlikely (sess_param->u.sym_sess.hash_mode !=VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH )) { sess_param->session_id = -VIRTIO_CRYPTO_NOTSUPP ; VC_LOG_ERR("Error transform session message (%i)",
@@ -362,7 +362,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, xform1.next = &xform2; - ret =transform_chain_param (&xform1, sess_param); + ret =transform_chain_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session message (%i)" , ret); sess_param->session_id = ret;
lib/vhost/vhost_user.h +29 -4
@@ -99,11 +99,10 @@ typedef struct VhostUserLog {/* Comply with Cryptodev-Linux */ #define VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH 512#define VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH 64 +#define VHOST_USER_CRYPTO_MAX_KEY_LENGTH 1024/* Same structure as vhost-user backend session info */ -typedef struct VhostUserCryptoSessionParam { - int64_t session_id; - uint32_t op_code; +typedef struct VhostUserCryptoSymSessionParam { uint32_t cipher_algo; uint32_t cipher_key_len; uint32_t hash_algo;
@@ -114,10 +113,36 @@ typedef struct VhostUserCryptoSessionParam {uint8_t dir;uint8_t hash_mode;uint8_t chaining_dir; -uint8_t *ciphe_key; +uint8_t *cipher_key;uint8_t *auth_key;uint8_t cipher_key_buf[VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH ];uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH ]; +} VhostUserCryptoSymSessionParam; + + +typedef struct VhostUserCryptoAsymRsaParam { +uint32_t padding_algo; +uint32_t hash_algo; +}VhostUserCryptoAsymRsaParam ; + +typedef struct VhostUserCryptoAsymSessionParam { +uint32_t algo; +uint32_t key_type; +uint32_t key_len; +uint8_t *key; +union { +VhostUserCryptoAsymRsaParam rsa; + } u; +uint8_t key_buf[VHOST_USER_CRYPTO_MAX_KEY_LENGTH ]; +}VhostUserCryptoAsymSessionParam ; + +typedef struct VhostUserCryptoSessionParam { +uint32_t op_code; +union { +VhostUserCryptoSymSessionParam sym_sess; +VhostUserCryptoAsymSessionParam asym_sess; + } u; +int64_t session_id; }VhostUserCryptoSessionParam ; typedef struct VhostUserVringArea {
Signature · 1 line
2.25.1
PATCH v5 3/5 examples/vhost_crypto: fix user callbacks
In reply to Gowrishankar MuthukrishnanIn order to handle new vhost user connection, use new_connection and destroy_connection callbacks.
--- examples/vhost_crypto/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
examples/vhost_crypto/main.c +2 -2
@@ -362,8 +362,8 @@ destroy_device(int vid) }static const struct rte_vhost_device_ops virtio_crypto_device_ops = { - .new_device = new_device, - .destroy_device = destroy_device, + .new_connection = new_device, + .destroy_connection = destroy_device, }; static int
Signature · 1 line
2.25.1
PATCH v5 4/5 vhost: support asymmetric RSA crypto ops
In reply to Gowrishankar MuthukrishnanSupport asymmetric RSA crypto operations in vhost-user.
---
v5:
- release notes
--- doc/guides/rel_notes/release_25_03.rst | 3 + lib/vhost/vhost_crypto.c | 486 +++++++++++++++++++++++-- lib/vhost/virtio_crypto.h | 67 ++++ 3 files changed, 521 insertions(+), 35 deletions(-)
doc/guides/rel_notes/release_25_03.rst +3 -0
@@ -151,6 +151,9 @@ New Features See the :doc:`../compressdevs/zsda` guide for more details on the new driver. +* **Updated vhost library.** + + Updated vhost library to support RSA crypto operations. Removed Items -------------
lib/vhost/vhost_crypto.c +451 -35
618 lines not on this page · raw message
lib/vhost/virtio_crypto.h +67 -0
115 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v5 5/5 examples/vhost_crypto: support asymmetric crypto
In reply to Gowrishankar MuthukrishnanSupport asymmetric crypto operations.
---
v5:
- doc update
--- doc/guides/sample_app_ug/vhost_crypto.rst | 5 +++ examples/vhost_crypto/main.c | 50 +++++++++++++++++------ 2 files changed, 43 insertions(+), 12 deletions(-)
doc/guides/sample_app_ug/vhost_crypto.rst +5 -0
@@ -33,6 +33,7 @@ Start the vhost_crypto example --socket-file lcore,PATH [--zero-copy] [--guest-polling] + [--asymmetric-crypto] where,
@@ -54,6 +55,10 @@ where, guest works in polling mode, thus will NOT notify the guest completion of processing. +* asymmetric-crypto: the presence of this item means the application + can handle the asymmetric crypto requests. When this option is used, + symmetric crypto requests can not be handled by the application. + The application requires that crypto devices capable of performing the specified crypto operation are available on application initialization. This means that HW crypto device/s must be bound to a DPDK driver or
examples/vhost_crypto/main.c +38 -12
129 lines not on this page · raw message
Signature · 1 line
2.25.1
v6 cover vhost: add RSA support
In reply to Gowrishankar MuthukrishnanThis patch series supports asymmetric RSA in vhost crypto library. It also includes changes to improve vhost crypto library:
* support newer QEMU versions.
* fix broken vhost_crypto example application.
* stabilize crypto fastpath operations.
Gowrishankar Muthukrishnan (5):
vhost: skip crypto op fetch before vring init
vhost: update vhost_user crypto session parameters examples/vhost_crypto: fix user callbacks
vhost: support asymmetric RSA crypto ops examples/vhost_crypto: support asymmetric crypto
doc/guides/rel_notes/release_25_03.rst | 3 + doc/guides/sample_app_ug/vhost_crypto.rst | 5 + examples/vhost_crypto/main.c | 54 ++- lib/vhost/vhost_crypto.c | 518 ++++++++++++++++++++-- lib/vhost/vhost_user.h | 33 +- lib/vhost/virtio_crypto.h | 67 +++ 6 files changed, 621 insertions(+), 59 deletions(-)
Signature · 1 line
2.25.1
PATCH v6 1/5 vhost: skip crypto op fetch before vring init
Until virtio avail ring is initialized (by VHOST_USER_SET_VRING_ADDR), worker thread should not try to fetch crypto op, which would lead to memory fault.
---
v6:
- added lock checks.
--- lib/vhost/vhost_crypto.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
lib/vhost/vhost_crypto.c +20 -0
@@ -8,6 +8,7 @@#include <rte_mbuf.h> #include <rte_cryptodev.h> +#include "iotlb.h" #include "rte_vhost_crypto.h" #include "vhost.h" #include "vhost_user.h"
@@ -1580,7 +1581,26 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, vq = dev->virtqueue[qid]; +if (unlikely (vq ==NULL )) { +VC_LOG_ERR ("Invalid virtqueue %u" , qid); +return 0 ; + } + +if (unlikely (rte_rwlock_read_trylock (&vq->access_lock) !=0 )) +return 0 ; + +vhost_user_iotlb_rd_lock (vq); +if (unlikely (!vq->access_ok)) { +VC_LOG_DBG ("Virtqueue %u vrings not yet initialized" , qid); +vhost_user_iotlb_rd_unlock (vq); +rte_rwlock_read_unlock (&vq->access_lock); +return 0 ; + } + avail_idx = *((volatile uint16_t *)&vq->avail->idx); +vhost_user_iotlb_rd_unlock (vq); +rte_rwlock_read_unlock (&vq->access_lock); + start_idx = vq->last_used_idx; count = avail_idx - start_idx; count =RTE_MIN (count,VHOST_CRYPTO_MAX_BURST_SIZE );
Signature · 1 line
2.25.1
Re: [v6 1/5] vhost: skip crypto op fetch before vring init
Hi Gowri,
Thanks for the change, but I think there is an issue with the locking, more below:
Quoted 42 lines · Gowrishankar Muthukrishnan
Until virtio avail ring is initialized (by
VHOST_USER_SET_VRING_ADDR), worker thread should not try to fetch crypto op, which would lead to memory fault.Fixes 939066d96563 ("vhost/crypto: add public function implementation")Signed-off-by Gowrishankar Muthukrishnan <[email protected]>Acked-by Akhil Goyal <[email protected]>---
v6:
- added lock checks.--- lib/vhost/vhost_crypto.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)lib/vhost/vhost_crypto.c +11
-0@@ -8,6 +8,7 @@#include <rte_mbuf.h> #include <rte_cryptodev.h> +#include "iotlb.h" #include "rte_vhost_crypto.h" #include "vhost.h" #include "vhost_user.h" @@ -1580,7 +1581,26 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, vq = dev->virtqueue[qid]; +if (unlikely (vq ==NULL )) { +VC_LOG_ERR ("Invalid virtqueue %u" , qid); +return 0 ; + } + +if (unlikely (rte_rwlock_read_trylock (&vq->access_lock) !=0 )) +return 0 ; + +vhost_user_iotlb_rd_lock (vq); +if (unlikely (!vq->access_ok)) {
lib/vhost/vhost_crypto.c rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, · line 1603
Quoted 10 lines
lib/vhost/vhost_crypto.c +9
-0+VC_LOG_DBG ("Virtqueue %u vrings not yet initialized" , qid); +vhost_user_iotlb_rd_unlock (vq); +rte_rwlock_read_unlock (&vq->access_lock); +return 0 ; + } + avail_idx = *((volatile uint16_t *)&vq->avail->idx); +vhost_user_iotlb_rd_unlock (vq); +rte_rwlock_read_unlock (&vq->access_lock); +
You should only unlock at the end of the function, otherwise there is not much protection.
Quoted 3 lines
lib/vhost/vhost_crypto.c +0
-0start_idx = vq->last_used_idx; count = avail_idx - start_idx; count =RTE_MIN (count,VHOST_CRYPTO_MAX_BURST_SIZE );
Re: [v6 1/5] vhost: skip crypto op fetch before vring init
Quoted 50 lines · Maxime Coquelin
Hi Gowri,
Thanks for the change, but I think there is an issue with the locking, more below:
Quoted 44 lines · Gowrishankar Muthukrishnan
Until virtio avail ring is initialized (by
VHOST_USER_SET_VRING_ADDR), worker thread should not try to fetch crypto op, which would lead to memory fault.Fixes 939066d96563 ("vhost/crypto: add public function implementation")Signed-off-by Gowrishankar Muthukrishnan <[email protected]>Acked-by Akhil Goyal <[email protected]>---
v6:
- added lock checks.
---
lib/vhost/vhost_crypto.c| 20 ++++++++++++++++++++1 file changed, 20 insertions(+)lib/vhost/vhost_crypto.c +15
-0@@ -8,6 +8,7 @@ #include <rte_mbuf.h> #include <rte_cryptodev.h> +#include "iotlb.h" #include "rte_vhost_crypto.h" #include "vhost.h" #include "vhost_user.h"@@ -1580,7 +1581,26 @@ rte_vhost_crypto_fetch_requests(int vid,uint32_t qid, vq = dev->virtqueue[qid]; + if (unlikely(vq == NULL)) { + VC_LOG_ERR("Invalid virtqueue %u", qid); + return 0; + } + + if (unlikely(rte_rwlock_read_trylock(&vq->access_lock) != 0)) + return 0; + + vhost_user_iotlb_rd_lock(vq); + if (unlikely(!vq->access_ok)) { + VC_LOG_DBG("Virtqueue %u vrings not yet initialized", qid); + vhost_user_iotlb_rd_unlock(vq); + rte_rwlock_read_unlock(&vq->access_lock); + return 0;
Quoted 8 lines
lib/vhost/vhost_crypto.c rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, · line 1603
Quoted 6 lines
lib/vhost/vhost_crypto.c +5
-0+ } + avail_idx = *((volatile uint16_t *)&vq->avail->idx); + vhost_user_iotlb_rd_unlock(vq); + rte_rwlock_read_unlock(&vq->access_lock); +You should only unlock at the end of the function, otherwise there is not much protection.
Ha, and also you should be able to remove: __rte_no_thread_safety_analysis /* FIXME: requires iotlb_lock? */ in vhost_crypto_process_one_req() once implemented.
Regards,
Maxime
Quoted 5 lines
Quoted 4 lines
lib/vhost/vhost_crypto.c +0
-0start_idx = vq->last_used_idx; count = avail_idx - start_idx; count = RTE_MIN(count, VHOST_CRYPTO_MAX_BURST_SIZE);
RE: [EXTERNAL] Re: [v6 1/5] vhost: skip crypto op fetch before vring init
Hi Maxime,
Quoted 8 lines
Quoted 3 lines
You should only unlock at the end of the function, otherwise there is not much protection.
Ha, and also you should be able to remove:
__rte_no_thread_safety_analysis/* FIXME: requiresiotlb_lock? */ invhost_crypto_process_one_req()once implemented.
Ack.
Thanks,
Gowrishankar.
RE: [EXTERNAL] Re: [v6 1/5] vhost: skip crypto op fetch before vring init
Quoted 6 lines
Quoted 5 lines
Ha, and also you should be able to remove:
__rte_no_thread_safety_analysis/* FIXME: requiresiotlb_lock? */ invhost_crypto_process_one_req()once implemented.
Removing it would break compilation for thread safety flag.
http://mails.dpdk.org/archives/test-report/2025-February/857515.html
It is due to local vc_req that is passed to func that requires iotlb lock
In vc_req->vq. Even though vc_req->vq is locked vq, GCC does not allow it, as I understand.
vc_req = &data_req; vc_req->desc_idx = desc_idx; vc_req->dev = vcrypto->dev; vc_req->vq = vq;
Thanks,
Gowrishankar
Re: [EXTERNAL] Re: [v6 1/5] vhost: skip crypto op fetch before vring init
Quoted 10 lines · Gowrishankar Muthukrishnan
Quoted 5 lines
Quoted 4 lines
Ha, and also you should be able to remove:
__rte_no_thread_safety_analysis/* FIXME: requiresiotlb_lock? */ invhost_crypto_process_one_req()once implemented.Removing it would break compilation for thread safety flag.
http://mails.dpdk.org/archives/test-report/2025-February/857515.htmlIt is due to local
vc_reqthat is passed to func that requires iotlb lock
Invc_req->vq. Even thoughvc_req->vqis locked vq, GCC does not allow it, as I understand.
*cough* clang.
Quoted 5 lines
vc_req = &data_req;
vc_req->desc_idx = desc_idx;
vc_req->dev = vcrypto->dev;
vc_req->vq = vq;The annotations won't handle this wrapping in the vc_req object. Just pass a vq object rather than the vc_req (which I don't see little point in having in the first place..) and adjust annotations.
Signature · 1 line
David Marchand
Re: [EXTERNAL] Re: [v6 1/5] vhost: skip crypto op fetch before vring init
Hi Gowri,
Quoted 16 lines · David Marchand
Quoted 10 lines · Gowrishankar Muthukrishnan
Quoted 5 lines
Quoted 4 lines
Ha, and also you should be able to remove:
__rte_no_thread_safety_analysis/* FIXME: requiresiotlb_lock? */ invhost_crypto_process_one_req()once implemented.Removing it would break compilation for thread safety flag.
http://mails.dpdk.org/archives/test-report/2025-February/857515.htmlIt is due to local
vc_reqthat is passed to func that requires iotlb lock
Invc_req->vq. Even thoughvc_req->vqis locked vq, GCC does not allow it, as I understand.*cough* clang.
Quoted 1 line
Quoted 10 lines
Quoted 4 lines
vc_req = &data_req; vc_req->desc_idx = desc_idx; vc_req->dev = vcrypto->dev; vc_req->vq = vq;The annotations won't handle this wrapping in the
vc_reqobject. Just pass a vq object rather than thevc_req(which I don't see little point in having in the first place..) and adjust annotations.
Before your series arrived, we were wondering if we should not deprecate Vhost crypto as it was not really maintained and we had no identified user.
Since it seems you are going to use it, which is great, would you commit to make the necessary changes to make it reliable? If yes, I would agree to take your v8 as is for v25.03 if proper rework is done for v25.07, would that work for you?
Maxime
RE: [EXTERNAL] Re: [v6 1/5] vhost: skip crypto op fetch before vring init
Hi Maxime,
Quoted 8 lines
Before your series arrived, we were wondering if we should not deprecate Vhost crypto as it was not really maintained and we had no identified user.
Since it seems you are going to use it, which is great, would you commit to make the necessary changes to make it reliable? If yes, I would agree to take your v8 as is for v25.03 if proper rework is done for v25.07, would that work for you?
I have sent v9 to include one additional patch to fix vhost_crypto_process_one_req() thread safety attribute. Please consider it.
Yes, if any other changes are required, we can assist going forward. We also believe this software backend needs to be reliable and hence can help test required virtio functionalities.
Thanks,
Gowrishankar
Regards,
Gowrishankar
Quoted 1 line
Maxime
Re: [EXTERNAL] Re: [v6 1/5] vhost: skip crypto op fetch before vring init
Hi Gowri,
Quoted 6 lines · Gowrishankar Muthukrishnan
Hi Maxime,
Quoted 4 lines
Before your series arrived, we were wondering if we should not deprecate Vhost crypto as it was not really maintained and we had no identified user.
Quoted 6 lines
Quoted 4 lines
Since it seems you are going to use it, which is great, would you commit to make the necessary changes to make it reliable? If yes, I would agree to take your v8 as is for v25.03 if proper rework is done for v25.07, would that work for you?
I have sent v9 to include one additional patch to fix
vhost_crypto_process_one_req()thread safety attribute. Please consider it.
Thanks! I will check it as soon as possible.
Quoted 3 lines
Yes, if any other changes are required, we can assist going forward. We also believe this software backend needs to be reliable and hence can help test required virtio functionalities.
That's great news.
Best regards,
Maxime
Quoted 8 lines
Thanks,
GowrishankarRegards,
GowrishankarQuoted 1 line
Maxime
RE: [EXTERNAL] Re: [v6 1/5] vhost: skip crypto op fetch before vring init
In reply to David MarchandHi David,
Quoted 8 lines
Quoted 3 lines
It is due to local
vc_reqthat is passed to func that requires iotlb lock Invc_req->vq. Even thoughvc_req->vqis locked vq, GCC does not allow it,as I understand.
*cough* clang.
Quoted 1 line
Quoted 9 lines
Quoted 4 lines
vc_req = &data_req; vc_req->desc_idx = desc_idx; vc_req->dev = vcrypto->dev; vc_req->vq = vq;The annotations won't handle this wrapping in the
vc_reqobject.
Just pass a vq object rather than thevc_req(which I don't see little point in having in the first place..) and adjust annotations.
Yes I thought about it initially, but then I had thought vhost_crypto_process_one_req() is only static and called with locks held. Anyway, I have come up with one additional patch in series to fix it specifically.
Thanks for your suggestion.
Regards,
Gowrishankar
Quoted 3 lines
--
David Marchand
PATCH v6 2/5 vhost: update vhost_user crypto session parameters
In reply to Gowrishankar MuthukrishnanAs per requirements on vhost_user spec, session id should be located at the end of session parameter.
Update VhostUserCryptoSessionParam structure to support newer QEMU versions (v9). Due to additional parameters added in QEMU, received payload from QEMU would be larger than existing payload. Hence, it would break parsing vhost_user messages.
This patch addresses both of the above problems.
--- lib/vhost/vhost_crypto.c | 12 ++++++------ lib/vhost/vhost_user.h | 33 +++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-)
lib/vhost/vhost_crypto.c +6 -6
@@ -238,7 +238,7 @@ struct vhost_crypto_data_req {static int transform_cipher_param (struct rte_crypto_sym_xform *xform, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {int ret;
@@ -274,7 +274,7 @@ transform_cipher_param(struct rte_crypto_sym_xform *xform,static int transform_chain_param (struct rte_crypto_sym_xform *xforms, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {struct rte_crypto_sym_xform *xform_cipher, *xform_auth;int ret;
@@ -342,10 +342,10 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto,struct rte_cryptodev_sym_session *session;int ret; -switch (sess_param->op_type) { +switch (sess_param->u.sym_sess.op_type) {case VIRTIO_CRYPTO_SYM_OP_NONE :case VIRTIO_CRYPTO_SYM_OP_CIPHER : - ret =transform_cipher_param (&xform1, sess_param); + ret =transform_cipher_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session msg (%i)" , ret); sess_param->session_id = ret;
@@ -353,7 +353,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, }break ;case VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING : -if (unlikely (sess_param->hash_mode != +if (unlikely (sess_param->u.sym_sess.hash_mode !=VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH )) { sess_param->session_id = -VIRTIO_CRYPTO_NOTSUPP ; VC_LOG_ERR("Error transform session message (%i)",
@@ -363,7 +363,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, xform1.next = &xform2; - ret =transform_chain_param (&xform1, sess_param); + ret =transform_chain_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session message (%i)" , ret); sess_param->session_id = ret;
lib/vhost/vhost_user.h +29 -4
@@ -99,11 +99,10 @@ typedef struct VhostUserLog {/* Comply with Cryptodev-Linux */ #define VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH 512#define VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH 64 +#define VHOST_USER_CRYPTO_MAX_KEY_LENGTH 1024/* Same structure as vhost-user backend session info */ -typedef struct VhostUserCryptoSessionParam { - int64_t session_id; - uint32_t op_code; +typedef struct VhostUserCryptoSymSessionParam { uint32_t cipher_algo; uint32_t cipher_key_len; uint32_t hash_algo;
@@ -114,10 +113,36 @@ typedef struct VhostUserCryptoSessionParam {uint8_t dir;uint8_t hash_mode;uint8_t chaining_dir; -uint8_t *ciphe_key; +uint8_t *cipher_key;uint8_t *auth_key;uint8_t cipher_key_buf[VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH ];uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH ]; +} VhostUserCryptoSymSessionParam; + + +typedef struct VhostUserCryptoAsymRsaParam { +uint32_t padding_algo; +uint32_t hash_algo; +}VhostUserCryptoAsymRsaParam ; + +typedef struct VhostUserCryptoAsymSessionParam { +uint32_t algo; +uint32_t key_type; +uint32_t key_len; +uint8_t *key; +union { +VhostUserCryptoAsymRsaParam rsa; + } u; +uint8_t key_buf[VHOST_USER_CRYPTO_MAX_KEY_LENGTH ]; +}VhostUserCryptoAsymSessionParam ; + +typedef struct VhostUserCryptoSessionParam { +uint32_t op_code; +union { +VhostUserCryptoSymSessionParam sym_sess; +VhostUserCryptoAsymSessionParam asym_sess; + } u; +int64_t session_id; }VhostUserCryptoSessionParam ; typedef struct VhostUserVringArea {
Signature · 1 line
2.25.1
PATCH v6 3/5 examples/vhost_crypto: fix user callbacks
In reply to Gowrishankar MuthukrishnanIn order to handle new vhost user connection, use new_connection and destroy_connection callbacks.
--- examples/vhost_crypto/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
examples/vhost_crypto/main.c +2 -2
@@ -362,8 +362,8 @@ destroy_device(int vid) }static const struct rte_vhost_device_ops virtio_crypto_device_ops = { - .new_device = new_device, - .destroy_device = destroy_device, + .new_connection = new_device, + .destroy_connection = destroy_device, }; static int
Signature · 1 line
2.25.1
PATCH v6 4/5 vhost: support asymmetric RSA crypto ops
In reply to Gowrishankar MuthukrishnanSupport asymmetric RSA crypto operations in vhost-user.
--- doc/guides/rel_notes/release_25_03.rst | 3 + lib/vhost/vhost_crypto.c | 486 +++++++++++++++++++++++-- lib/vhost/virtio_crypto.h | 67 ++++ 3 files changed, 521 insertions(+), 35 deletions(-)
doc/guides/rel_notes/release_25_03.rst +3 -0
@@ -151,6 +151,9 @@ New Features See the :doc:`../compressdevs/zsda` guide for more details on the new driver. +* **Updated vhost library.** + + Updated vhost library to support RSA crypto operations. Removed Items -------------
lib/vhost/vhost_crypto.c +451 -35
618 lines not on this page · raw message
lib/vhost/virtio_crypto.h +67 -0
115 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v6 5/5 examples/vhost_crypto: support asymmetric crypto
In reply to Gowrishankar MuthukrishnanSupport asymmetric crypto operations.
--- doc/guides/sample_app_ug/vhost_crypto.rst | 5 +++ examples/vhost_crypto/main.c | 50 +++++++++++++++++------ 2 files changed, 43 insertions(+), 12 deletions(-)
doc/guides/sample_app_ug/vhost_crypto.rst +5 -0
@@ -33,6 +33,7 @@ Start the vhost_crypto example --socket-file lcore,PATH [--zero-copy] [--guest-polling] + [--asymmetric-crypto] where,
@@ -54,6 +55,10 @@ where, guest works in polling mode, thus will NOT notify the guest completion of processing. +* asymmetric-crypto: the presence of this item means the application + can handle the asymmetric crypto requests. When this option is used, + symmetric crypto requests can not be handled by the application. + The application requires that crypto devices capable of performing the specified crypto operation are available on application initialization. This means that HW crypto device/s must be bound to a DPDK driver or
examples/vhost_crypto/main.c +38 -12
129 lines not on this page · raw message
Signature · 1 line
2.25.1
v7 cover vhost: add RSA support
In reply to Gowrishankar MuthukrishnanThis patch series supports asymmetric RSA in vhost crypto library. It also includes changes to improve vhost crypto library:
* support newer QEMU versions.
* fix broken vhost_crypto example application.
* stabilize crypto fastpath operations.
Gowrishankar Muthukrishnan (5):
vhost: skip crypto op fetch before vring init
vhost: update vhost_user crypto session parameters examples/vhost_crypto: fix user callbacks
vhost: support asymmetric RSA crypto ops examples/vhost_crypto: support asymmetric crypto
doc/guides/rel_notes/release_25_03.rst | 3 + doc/guides/sample_app_ug/vhost_crypto.rst | 5 + examples/vhost_crypto/main.c | 54 ++- lib/vhost/vhost_crypto.c | 524 ++++++++++++++++++++-- lib/vhost/vhost_user.h | 33 +- lib/vhost/virtio_crypto.h | 67 +++ 6 files changed, 623 insertions(+), 63 deletions(-)
Signature · 1 line
2.25.1
PATCH v7 1/5 vhost: skip crypto op fetch before vring init
Until virtio avail ring is initialized (by VHOST_USER_SET_VRING_ADDR), worker thread should not try to fetch crypto op, which would lead to memory fault.
---
v7:
- updated locks in fetch req func.
--- lib/vhost/vhost_crypto.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
lib/vhost/vhost_crypto.c +22 -4
@@ -8,6 +8,7 @@#include <rte_mbuf.h> #include <rte_cryptodev.h> +#include "iotlb.h" #include "rte_vhost_crypto.h" #include "vhost.h" #include "vhost_user.h"
@@ -1131,7 +1132,6 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, struct vhost_virtqueue *vq, struct rte_crypto_op *op, struct vring_desc *head, struct vhost_crypto_desc *descs, uint16_t desc_idx) - __rte_no_thread_safety_analysis /* FIXME: requires iotlb_lock? */ { struct vhost_crypto_data_req *vc_req = rte_mbuf_to_priv(op->sym->m_src);struct rte_cryptodev_sym_session *session;
@@ -1580,6 +1580,20 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, vq = dev->virtqueue[qid]; +if (unlikely (vq ==NULL )) { +VC_LOG_ERR ("Invalid virtqueue %u" , qid); +return 0 ; + } + +if (unlikely (rte_rwlock_read_trylock (&vq->access_lock) !=0 )) +return 0 ; + +vhost_user_iotlb_rd_lock (vq); +if (unlikely (!vq->access_ok)) { +VC_LOG_DBG ("Virtqueue %u vrings not yet initialized" , qid); + goto out_unlock; + } + avail_idx = *((volatile uint16_t *)&vq->avail->idx); start_idx = vq->last_used_idx; count = avail_idx - start_idx;
@@ -1587,7 +1601,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, count =RTE_MIN (count, nb_ops);if (unlikely (count ==0 )) -return 0 ; + goto out_unlock;/* for zero copy, we need 2 empty mbufs for src and dst, otherwise * we need only 1 mbuf as src and dst
@@ -1597,7 +1611,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,if (unlikely (rte_mempool_get_bulk (vcrypto->mbuf_pool, (void **)mbufs, count *2 ) <0 )) {VC_LOG_ERR ("Insufficient memory" ); -return 0 ; + goto out_unlock; }for (i =0 ; i < count; i++) {
@@ -1627,7 +1641,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,if (unlikely (rte_mempool_get_bulk (vcrypto->mbuf_pool, (void **)mbufs, count) <0 )) {VC_LOG_ERR ("Insufficient memory" ); -return 0 ; + goto out_unlock; }for (i =0 ; i < count; i++) {
@@ -1656,6 +1670,10 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, vq->last_used_idx += i; +out_unlock: +vhost_user_iotlb_rd_unlock (vq); +rte_rwlock_read_unlock (&vq->access_lock); +return i; }
Signature · 1 line
2.25.1
PATCH v7 2/5 vhost: update vhost_user crypto session parameters
In reply to Gowrishankar MuthukrishnanAs per requirements on vhost_user spec, session id should be located at the end of session parameter.
Update VhostUserCryptoSessionParam structure to support newer QEMU versions (v9). Due to additional parameters added in QEMU, received payload from QEMU would be larger than existing payload. Hence, it would break parsing vhost_user messages.
This patch addresses both of the above problems.
--- lib/vhost/vhost_crypto.c | 12 ++++++------ lib/vhost/vhost_user.h | 33 +++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-)
lib/vhost/vhost_crypto.c +6 -6
@@ -238,7 +238,7 @@ struct vhost_crypto_data_req {static int transform_cipher_param (struct rte_crypto_sym_xform *xform, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {int ret;
@@ -274,7 +274,7 @@ transform_cipher_param(struct rte_crypto_sym_xform *xform,static int transform_chain_param (struct rte_crypto_sym_xform *xforms, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {struct rte_crypto_sym_xform *xform_cipher, *xform_auth;int ret;
@@ -342,10 +342,10 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto,struct rte_cryptodev_sym_session *session;int ret; -switch (sess_param->op_type) { +switch (sess_param->u.sym_sess.op_type) {case VIRTIO_CRYPTO_SYM_OP_NONE :case VIRTIO_CRYPTO_SYM_OP_CIPHER : - ret =transform_cipher_param (&xform1, sess_param); + ret =transform_cipher_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session msg (%i)" , ret); sess_param->session_id = ret;
@@ -353,7 +353,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, }break ;case VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING : -if (unlikely (sess_param->hash_mode != +if (unlikely (sess_param->u.sym_sess.hash_mode !=VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH )) { sess_param->session_id = -VIRTIO_CRYPTO_NOTSUPP ; VC_LOG_ERR("Error transform session message (%i)",
@@ -363,7 +363,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, xform1.next = &xform2; - ret =transform_chain_param (&xform1, sess_param); + ret =transform_chain_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session message (%i)" , ret); sess_param->session_id = ret;
lib/vhost/vhost_user.h +29 -4
@@ -99,11 +99,10 @@ typedef struct VhostUserLog {/* Comply with Cryptodev-Linux */ #define VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH 512#define VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH 64 +#define VHOST_USER_CRYPTO_MAX_KEY_LENGTH 1024/* Same structure as vhost-user backend session info */ -typedef struct VhostUserCryptoSessionParam { - int64_t session_id; - uint32_t op_code; +typedef struct VhostUserCryptoSymSessionParam { uint32_t cipher_algo; uint32_t cipher_key_len; uint32_t hash_algo;
@@ -114,10 +113,36 @@ typedef struct VhostUserCryptoSessionParam {uint8_t dir;uint8_t hash_mode;uint8_t chaining_dir; -uint8_t *ciphe_key; +uint8_t *cipher_key;uint8_t *auth_key;uint8_t cipher_key_buf[VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH ];uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH ]; +} VhostUserCryptoSymSessionParam; + + +typedef struct VhostUserCryptoAsymRsaParam { +uint32_t padding_algo; +uint32_t hash_algo; +}VhostUserCryptoAsymRsaParam ; + +typedef struct VhostUserCryptoAsymSessionParam { +uint32_t algo; +uint32_t key_type; +uint32_t key_len; +uint8_t *key; +union { +VhostUserCryptoAsymRsaParam rsa; + } u; +uint8_t key_buf[VHOST_USER_CRYPTO_MAX_KEY_LENGTH ]; +}VhostUserCryptoAsymSessionParam ; + +typedef struct VhostUserCryptoSessionParam { +uint32_t op_code; +union { +VhostUserCryptoSymSessionParam sym_sess; +VhostUserCryptoAsymSessionParam asym_sess; + } u; +int64_t session_id; }VhostUserCryptoSessionParam ; typedef struct VhostUserVringArea {
Signature · 1 line
2.25.1
PATCH v7 3/5 examples/vhost_crypto: fix user callbacks
In reply to Gowrishankar MuthukrishnanIn order to handle new vhost user connection, use new_connection and destroy_connection callbacks.
--- examples/vhost_crypto/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
examples/vhost_crypto/main.c +2 -2
@@ -362,8 +362,8 @@ destroy_device(int vid) }static const struct rte_vhost_device_ops virtio_crypto_device_ops = { - .new_device = new_device, - .destroy_device = destroy_device, + .new_connection = new_device, + .destroy_connection = destroy_device, }; static int
Signature · 1 line
2.25.1
PATCH v7 4/5 vhost: support asymmetric RSA crypto ops
In reply to Gowrishankar MuthukrishnanSupport asymmetric RSA crypto operations in vhost-user.
--- doc/guides/rel_notes/release_25_03.rst | 3 + lib/vhost/vhost_crypto.c | 486 +++++++++++++++++++++++-- lib/vhost/virtio_crypto.h | 67 ++++ 3 files changed, 521 insertions(+), 35 deletions(-)
doc/guides/rel_notes/release_25_03.rst +3 -0
@@ -151,6 +151,9 @@ New Features See the :doc:`../compressdevs/zsda` guide for more details on the new driver. +* **Updated vhost library.** + + Updated vhost library to support RSA crypto operations. Removed Items -------------
lib/vhost/vhost_crypto.c +451 -35
618 lines not on this page · raw message
lib/vhost/virtio_crypto.h +67 -0
115 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v7 5/5 examples/vhost_crypto: support asymmetric crypto
In reply to Gowrishankar MuthukrishnanSupport asymmetric crypto operations.
--- doc/guides/sample_app_ug/vhost_crypto.rst | 5 +++ examples/vhost_crypto/main.c | 50 +++++++++++++++++------ 2 files changed, 43 insertions(+), 12 deletions(-)
doc/guides/sample_app_ug/vhost_crypto.rst +5 -0
@@ -33,6 +33,7 @@ Start the vhost_crypto example --socket-file lcore,PATH [--zero-copy] [--guest-polling] + [--asymmetric-crypto] where,
@@ -54,6 +55,10 @@ where, guest works in polling mode, thus will NOT notify the guest completion of processing. +* asymmetric-crypto: the presence of this item means the application + can handle the asymmetric crypto requests. When this option is used, + symmetric crypto requests can not be handled by the application. + The application requires that crypto devices capable of performing the specified crypto operation are available on application initialization. This means that HW crypto device/s must be bound to a DPDK driver or
examples/vhost_crypto/main.c +38 -12
129 lines not on this page · raw message
Signature · 1 line
2.25.1
v8 cover vhost: add RSA support
In reply to Gowrishankar MuthukrishnanThis patch series supports asymmetric RSA in vhost crypto library. It also includes changes to improve vhost crypto library:
* support newer QEMU versions.
* fix broken vhost_crypto example application.
* stabilize crypto fastpath operations.
Gowrishankar Muthukrishnan (5):
vhost: skip crypto op fetch before vring init
vhost: update vhost_user crypto session parameters examples/vhost_crypto: fix user callbacks
vhost: support asymmetric RSA crypto ops examples/vhost_crypto: support asymmetric crypto
doc/guides/rel_notes/release_25_03.rst | 3 + doc/guides/sample_app_ug/vhost_crypto.rst | 5 + examples/vhost_crypto/main.c | 54 ++- lib/vhost/vhost_crypto.c | 523 ++++++++++++++++++++-- lib/vhost/vhost_user.h | 33 +- lib/vhost/virtio_crypto.h | 67 +++ 6 files changed, 623 insertions(+), 62 deletions(-)
Signature · 1 line
2.25.1
PATCH v8 1/5 vhost: skip crypto op fetch before vring init
Until virtio avail ring is initialized (by VHOST_USER_SET_VRING_ADDR), worker thread should not try to fetch crypto op, which would lead to memory fault.
---
v8:
- fix CI issue.
--- lib/vhost/vhost_crypto.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
lib/vhost/vhost_crypto.c +22 -3
@@ -8,6 +8,7 @@#include <rte_mbuf.h> #include <rte_cryptodev.h> +#include "iotlb.h" #include "rte_vhost_crypto.h" #include "vhost.h" #include "vhost_user.h"
@@ -1580,6 +1581,20 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, vq = dev->virtqueue[qid]; +if (unlikely (vq ==NULL )) { +VC_LOG_ERR ("Invalid virtqueue %u" , qid); +return 0 ; + } + +if (unlikely (rte_rwlock_read_trylock (&vq->access_lock) !=0 )) +return 0 ; + +vhost_user_iotlb_rd_lock (vq); +if (unlikely (!vq->access_ok)) { +VC_LOG_DBG ("Virtqueue %u vrings not yet initialized" , qid); + goto out_unlock; + } + avail_idx = *((volatile uint16_t *)&vq->avail->idx); start_idx = vq->last_used_idx; count = avail_idx - start_idx;
@@ -1587,7 +1602,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, count =RTE_MIN (count, nb_ops);if (unlikely (count ==0 )) -return 0 ; + goto out_unlock;/* for zero copy, we need 2 empty mbufs for src and dst, otherwise * we need only 1 mbuf as src and dst
@@ -1597,7 +1612,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,if (unlikely (rte_mempool_get_bulk (vcrypto->mbuf_pool, (void **)mbufs, count *2 ) <0 )) {VC_LOG_ERR ("Insufficient memory" ); -return 0 ; + goto out_unlock; }for (i =0 ; i < count; i++) {
@@ -1627,7 +1642,7 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid,if (unlikely (rte_mempool_get_bulk (vcrypto->mbuf_pool, (void **)mbufs, count) <0 )) {VC_LOG_ERR ("Insufficient memory" ); -return 0 ; + goto out_unlock; }for (i =0 ; i < count; i++) {
@@ -1656,6 +1671,10 @@ rte_vhost_crypto_fetch_requests(int vid, uint32_t qid, vq->last_used_idx += i; +out_unlock: +vhost_user_iotlb_rd_unlock (vq); +rte_rwlock_read_unlock (&vq->access_lock); +return i; }
Signature · 1 line
2.25.1
PATCH v8 2/5 vhost: update vhost_user crypto session parameters
In reply to Gowrishankar MuthukrishnanAs per requirements on vhost_user spec, session id should be located at the end of session parameter.
Update VhostUserCryptoSessionParam structure to support newer QEMU versions (v9). Due to additional parameters added in QEMU, received payload from QEMU would be larger than existing payload. Hence, it would break parsing vhost_user messages.
This patch addresses both of the above problems.
--- lib/vhost/vhost_crypto.c | 12 ++++++------ lib/vhost/vhost_user.h | 33 +++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 10 deletions(-)
lib/vhost/vhost_crypto.c +6 -6
@@ -238,7 +238,7 @@ struct vhost_crypto_data_req {static int transform_cipher_param (struct rte_crypto_sym_xform *xform, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {int ret;
@@ -274,7 +274,7 @@ transform_cipher_param(struct rte_crypto_sym_xform *xform,static int transform_chain_param (struct rte_crypto_sym_xform *xforms, -VhostUserCryptoSessionParam *param) +VhostUserCryptoSymSessionParam *param) {struct rte_crypto_sym_xform *xform_cipher, *xform_auth;int ret;
@@ -342,10 +342,10 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto,struct rte_cryptodev_sym_session *session;int ret; -switch (sess_param->op_type) { +switch (sess_param->u.sym_sess.op_type) {case VIRTIO_CRYPTO_SYM_OP_NONE :case VIRTIO_CRYPTO_SYM_OP_CIPHER : - ret =transform_cipher_param (&xform1, sess_param); + ret =transform_cipher_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session msg (%i)" , ret); sess_param->session_id = ret;
@@ -353,7 +353,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, }break ;case VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING : -if (unlikely (sess_param->hash_mode != +if (unlikely (sess_param->u.sym_sess.hash_mode !=VIRTIO_CRYPTO_SYM_HASH_MODE_AUTH )) { sess_param->session_id = -VIRTIO_CRYPTO_NOTSUPP ; VC_LOG_ERR("Error transform session message (%i)",
@@ -363,7 +363,7 @@ vhost_crypto_create_sess(struct vhost_crypto *vcrypto, xform1.next = &xform2; - ret =transform_chain_param (&xform1, sess_param); + ret =transform_chain_param (&xform1, &sess_param->u.sym_sess);if (unlikely (ret)) {VC_LOG_ERR ("Error transform session message (%i)" , ret); sess_param->session_id = ret;
lib/vhost/vhost_user.h +29 -4
@@ -99,11 +99,10 @@ typedef struct VhostUserLog {/* Comply with Cryptodev-Linux */ #define VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH 512#define VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH 64 +#define VHOST_USER_CRYPTO_MAX_KEY_LENGTH 1024/* Same structure as vhost-user backend session info */ -typedef struct VhostUserCryptoSessionParam { - int64_t session_id; - uint32_t op_code; +typedef struct VhostUserCryptoSymSessionParam { uint32_t cipher_algo; uint32_t cipher_key_len; uint32_t hash_algo;
@@ -114,10 +113,36 @@ typedef struct VhostUserCryptoSessionParam {uint8_t dir;uint8_t hash_mode;uint8_t chaining_dir; -uint8_t *ciphe_key; +uint8_t *cipher_key;uint8_t *auth_key;uint8_t cipher_key_buf[VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH ];uint8_t auth_key_buf[VHOST_USER_CRYPTO_MAX_HMAC_KEY_LENGTH ]; +} VhostUserCryptoSymSessionParam; + + +typedef struct VhostUserCryptoAsymRsaParam { +uint32_t padding_algo; +uint32_t hash_algo; +}VhostUserCryptoAsymRsaParam ; + +typedef struct VhostUserCryptoAsymSessionParam { +uint32_t algo; +uint32_t key_type; +uint32_t key_len; +uint8_t *key; +union { +VhostUserCryptoAsymRsaParam rsa; + } u; +uint8_t key_buf[VHOST_USER_CRYPTO_MAX_KEY_LENGTH ]; +}VhostUserCryptoAsymSessionParam ; + +typedef struct VhostUserCryptoSessionParam { +uint32_t op_code; +union { +VhostUserCryptoSymSessionParam sym_sess; +VhostUserCryptoAsymSessionParam asym_sess; + } u; +int64_t session_id; }VhostUserCryptoSessionParam ; typedef struct VhostUserVringArea {
Signature · 1 line
2.25.1
PATCH v8 3/5 examples/vhost_crypto: fix user callbacks
In reply to Gowrishankar MuthukrishnanIn order to handle new vhost user connection, use new_connection and destroy_connection callbacks.
--- examples/vhost_crypto/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
examples/vhost_crypto/main.c +2 -2
@@ -362,8 +362,8 @@ destroy_device(int vid) }static const struct rte_vhost_device_ops virtio_crypto_device_ops = { - .new_device = new_device, - .destroy_device = destroy_device, + .new_connection = new_device, + .destroy_connection = destroy_device, }; static int
Signature · 1 line
2.25.1
PATCH v8 4/5 vhost: support asymmetric RSA crypto ops
In reply to Gowrishankar MuthukrishnanSupport asymmetric RSA crypto operations in vhost-user.
--- doc/guides/rel_notes/release_25_03.rst | 3 + lib/vhost/vhost_crypto.c | 486 +++++++++++++++++++++++-- lib/vhost/virtio_crypto.h | 67 ++++ 3 files changed, 521 insertions(+), 35 deletions(-)
doc/guides/rel_notes/release_25_03.rst +3 -0
@@ -151,6 +151,9 @@ New Features See the :doc:`../compressdevs/zsda` guide for more details on the new driver. +* **Updated vhost library.** + + Updated vhost library to support RSA crypto operations. Removed Items -------------
lib/vhost/vhost_crypto.c +451 -35
618 lines not on this page · raw message
lib/vhost/virtio_crypto.h +67 -0
115 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v8 5/5 examples/vhost_crypto: support asymmetric crypto
In reply to Gowrishankar MuthukrishnanSupport asymmetric crypto operations.
--- doc/guides/sample_app_ug/vhost_crypto.rst | 5 +++ examples/vhost_crypto/main.c | 50 +++++++++++++++++------ 2 files changed, 43 insertions(+), 12 deletions(-)
doc/guides/sample_app_ug/vhost_crypto.rst +5 -0
@@ -33,6 +33,7 @@ Start the vhost_crypto example --socket-file lcore,PATH [--zero-copy] [--guest-polling] + [--asymmetric-crypto] where,
@@ -54,6 +55,10 @@ where, guest works in polling mode, thus will NOT notify the guest completion of processing. +* asymmetric-crypto: the presence of this item means the application + can handle the asymmetric crypto requests. When this option is used, + symmetric crypto requests can not be handled by the application. + The application requires that crypto devices capable of performing the specified crypto operation are available on application initialization. This means that HW crypto device/s must be bound to a DPDK driver or
examples/vhost_crypto/main.c +38 -12
129 lines not on this page · raw message
Signature · 1 line
2.25.1
v9 cover vhost: add RSA support
In reply to Gowrishankar MuthukrishnanThis patch series supports asymmetric RSA in vhost crypto library. It also includes changes to improve vhost crypto library:
* support newer QEMU versions.
* fix broken vhost_crypto example application.
* stabilize crypto fastpath operations.
v9:
- new patch 1/6
Gowrishankar Muthukrishnan (6):
vhost: fix thread safety checks for vhost crypto data req
vhost: skip crypto op fetch before vring init
vhost: update vhost_user crypto session parameters examples/vhost_crypto: fix user callbacks
vhost: support asymmetric RSA crypto ops examples/vhost_crypto: support asymmetric crypto
doc/guides/rel_notes/release_25_03.rst | 3 + doc/guides/sample_app_ug/vhost_crypto.rst | 5 + examples/vhost_crypto/main.c | 54 +- lib/vhost/vhost_crypto.c | 597 +++++++++++++++++++--- lib/vhost/vhost_user.h | 33 +- lib/vhost/virtio_crypto.h | 67 +++ 6 files changed, 664 insertions(+), 95 deletions(-)
Signature · 1 line
2.25.1
PATCH v9 1/6 vhost: fix thread safety checks for vhost crypto data req
For thread safety check to succeed (as in clang), calling function should ensure vq->iotlb_lock locked before passing vq to a function that has thread safety attribute, in vhost crypto implementation.
When vhost_crypto_data_req is local and its vq is pointer to a locked vq, clang does not recognise this inherited lock and stops compilation. This patch explicitly uses vhost_virtqueue where ever required and fulfills thread safety checks.
--- lib/vhost/vhost_crypto.c | 76 ++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 35 deletions(-)
lib/vhost/vhost_crypto.c +41 -35
@@ -43,8 +43,8 @@ RTE_LOG_REGISTER_SUFFIX(vhost_crypto_logtype, crypto, INFO); (1ULL << VIRTIO_F_VERSION_1) | \ (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)) -#define IOVA_TO_VVA (t, r, a, l, p) \ - ((t)(uintptr_t)vhost_iova_to_vva(r->dev, r->vq, a, l, p)) +#define IOVA_TO_VVA (t, dev, vq, a, l, p) \ + ((t)(uintptr_t)vhost_iova_to_vva(dev, vq, a, l, p))/* * vhost_crypto_desc is used to copy original vring_desc to the local buffer
@@ -488,10 +488,10 @@ find_write_desc(struct vhost_crypto_desc *head, struct vhost_crypto_desc *desc, } static __rte_always_inline struct virtio_crypto_inhdr * -reach_inhdr (struct vhost_crypto_data_req *vc_req, +reach_inhdr (struct virtio_net *dev,struct vhost_virtqueue *vq,struct vhost_crypto_desc *head,uint32_t max_n_descs) - __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(vq->iotlb_lock) {struct virtio_crypto_inhdr *inhdr;struct vhost_crypto_desc *last = head + (max_n_descs -1 );
@@ -500,8 +500,8 @@ reach_inhdr(struct vhost_crypto_data_req *vc_req,if (unlikely (dlen !=sizeof (*inhdr)))return NULL ; - inhdr = IOVA_TO_VVA(struct virtio_crypto_inhdr *, vc_req, last->addr, - &dlen,VHOST_ACCESS_WO ); + inhdr = IOVA_TO_VVA(struct virtio_crypto_inhdr *, dev, vq, + last->addr, &dlen,VHOST_ACCESS_WO );if (unlikely (!inhdr || dlen != last->len))return NULL ;
@@ -543,7 +543,8 @@ get_data_ptr(struct vhost_crypto_data_req *vc_req,void *data;uint64_t dlen = cur_desc->len; - data = IOVA_TO_VVA(void *, vc_req, cur_desc->addr, &dlen, perm); + data = IOVA_TO_VVA(void *, vc_req->dev, vc_req->vq, + cur_desc->addr, &dlen, perm);if (unlikely (!data || dlen != cur_desc->len)) {VC_LOG_ERR ("Failed to map object" );return NULL ;
@@ -553,9 +554,9 @@ get_data_ptr(struct vhost_crypto_data_req *vc_req, } static __rte_always_inline uint32_t -copy_data_from_desc (void *dst,struct vhost_crypto_data_req *vc_req, -struct vhost_crypto_desc *desc,uint32_t size) - __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) +copy_data_from_desc (void *dst,struct virtio_net *dev, +struct vhost_virtqueue *vq,struct vhost_crypto_desc *desc,uint32_t size) + __rte_requires_shared_capability(vq->iotlb_lock) {uint64_t remain;uint64_t addr;
@@ -567,7 +568,8 @@ copy_data_from_desc(void *dst, struct vhost_crypto_data_req *vc_req,void *src; len = remain; - src = IOVA_TO_VVA(void *, vc_req, addr, &len, VHOST_ACCESS_RO); + src = IOVA_TO_VVA(void *, dev, vq, + addr, &len,VHOST_ACCESS_RO );if (unlikely (src ==NULL || len ==0 ))return 0 ;
@@ -583,10 +585,10 @@ copy_data_from_desc(void *dst, struct vhost_crypto_data_req *vc_req, static __rte_always_inline int -copy_data (void *data,struct vhost_crypto_data_req *vc_req, +copy_data (void *data,struct virtio_net *dev,struct vhost_virtqueue *vq,struct vhost_crypto_desc *head,struct vhost_crypto_desc **cur_desc,uint32_t size,uint32_t max_n_descs) - __rte_requires_shared_capability(&vc_req->vq->iotlb_lock) + __rte_requires_shared_capability(vq->iotlb_lock) {struct vhost_crypto_desc *desc = *cur_desc;uint32_t left = size;
@@ -594,7 +596,7 @@ copy_data(void *data, struct vhost_crypto_data_req *vc_req, do { uint32_t copied; - copied = copy_data_from_desc(data, vc_req, desc, left); + copied = copy_data_from_desc(data, dev, vq, desc, left); if (copied == 0) return -1; left -= copied;
@@ -689,8 +691,8 @@ prepare_write_back_data(struct vhost_crypto_data_req *vc_req,if (likely (desc->len > offset)) { wb_data->src = src + offset; dlen = desc->len; - dst = IOVA_TO_VVA(uint8_t *, vc_req, desc->addr, - &dlen,VHOST_ACCESS_RW ); + dst = IOVA_TO_VVA(uint8_t *, vc_req->dev, vc_req->vq, + desc->addr, &dlen,VHOST_ACCESS_RW );if (unlikely (!dst || dlen != desc->len)) {VC_LOG_ERR ("Failed to map descriptor" ); goto error_exit;
@@ -731,8 +733,8 @@ prepare_write_back_data(struct vhost_crypto_data_req *vc_req, } dlen = desc->len; - dst = IOVA_TO_VVA(uint8_t *, vc_req, desc->addr, &dlen, -VHOST_ACCESS_RW ) + offset; + dst = IOVA_TO_VVA(uint8_t *, vc_req->dev, vc_req->vq, + desc->addr, &dlen,VHOST_ACCESS_RW ) + offset;if (unlikely (dst ==NULL || dlen != desc->len)) {VC_LOG_ERR ("Failed to map descriptor" ); goto error_exit;
@@ -804,7 +806,7 @@ prepare_sym_cipher_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,/* prepare */ /* iv */ -if (unlikely (copy_data (iv_data, vc_req, head, &desc, +if (unlikely (copy_data (iv_data, vcrypto->dev, vc_req->vq, head, &desc, cipher->para.iv_len, max_n_descs))) {VC_LOG_ERR ("Incorrect virtio descriptor" ); ret =VIRTIO_CRYPTO_BADMSG ;
@@ -835,8 +837,8 @@ prepare_sym_cipher_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op, vc_req->wb_pool = vcrypto->wb_pool; m_src->data_len = cipher->para.src_data_len; if (unlikely(copy_data(rte_pktmbuf_mtod(m_src, uint8_t *), - vc_req, head, &desc, cipher->para.src_data_len, - max_n_descs) <0 )) { + vcrypto->dev, vc_req->vq, head, &desc, + cipher->para.src_data_len, max_n_descs) <0 )) {VC_LOG_ERR ("Incorrect virtio descriptor" ); ret =VIRTIO_CRYPTO_BADMSG ; goto error_exit;
@@ -960,7 +962,7 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op,/* prepare */ /* iv */ -if (unlikely (copy_data (iv_data, vc_req, head, &desc, +if (unlikely (copy_data (iv_data, vcrypto->dev, vc_req->vq, head, &desc, chain->para.iv_len, max_n_descs) <0 )) {VC_LOG_ERR ("Incorrect virtio descriptor" ); ret =VIRTIO_CRYPTO_BADMSG ;
@@ -992,8 +994,8 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op, vc_req->wb_pool = vcrypto->wb_pool; m_src->data_len = chain->para.src_data_len; if (unlikely(copy_data(rte_pktmbuf_mtod(m_src, uint8_t *), - vc_req, head, &desc, chain->para.src_data_len, - max_n_descs) <0 )) { + vcrypto->dev, vc_req->vq, head, &desc, + chain->para.src_data_len, max_n_descs) <0 )) {VC_LOG_ERR ("Incorrect virtio descriptor" ); ret =VIRTIO_CRYPTO_BADMSG ; goto error_exit;
@@ -1076,8 +1078,8 @@ prepare_sym_chain_op(struct vhost_crypto *vcrypto, struct rte_crypto_op *op, goto error_exit; } -if (unlikely (copy_data (digest_addr, vc_req, head, &digest_desc, - chain->para.hash_result_len, +if (unlikely (copy_data (digest_addr, vcrypto->dev, vc_req->vq, head, + &digest_desc, chain->para.hash_result_len, max_n_descs) <0 )) {VC_LOG_ERR ("Incorrect virtio descriptor" ); ret =VIRTIO_CRYPTO_BADMSG ;
@@ -1131,7 +1133,7 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, struct vhost_virtqueue *vq, struct rte_crypto_op *op, struct vring_desc *head, struct vhost_crypto_desc *descs, uint16_t desc_idx) - __rte_no_thread_safety_analysis /* FIXME: requires iotlb_lock? */ + __rte_requires_shared_capability(vq->iotlb_lock) { struct vhost_crypto_data_req *vc_req = rte_mbuf_to_priv(op->sym->m_src);struct rte_cryptodev_sym_session *session;
@@ -1154,8 +1156,8 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, } dlen = head->len; - src_desc = IOVA_TO_VVA(struct vring_desc *, vc_req, head->addr, - &dlen,VHOST_ACCESS_RO ); + src_desc = IOVA_TO_VVA(struct vring_desc *, vc_req->dev, vq, + head->addr, &dlen,VHOST_ACCESS_RO );if (unlikely (!src_desc || dlen != head->len)) {VC_LOG_ERR ("Invalid descriptor" );return -1 ;
@@ -1175,8 +1177,8 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, }if (inhdr_desc->len !=sizeof (*inhdr))return -1 ; - inhdr = IOVA_TO_VVA(struct virtio_crypto_inhdr *, - vc_req, inhdr_desc->addr, &dlen, + inhdr = IOVA_TO_VVA(struct virtio_crypto_inhdr *, vc_req->dev, + vq, inhdr_desc->addr, &dlen,VHOST_ACCESS_WO );if (unlikely (!inhdr || dlen != inhdr_desc->len))return -1 ;
@@ -1213,7 +1215,7 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, goto error_exit; } -if (unlikely (copy_data (&req, vc_req, descs, &desc,sizeof (req), +if (unlikely (copy_data (&req, vcrypto->dev, vq, descs, &desc,sizeof (req), max_n_descs) <0 )) { err =VIRTIO_CRYPTO_BADMSG ;VC_LOG_ERR ("Invalid descriptor" );
@@ -1257,14 +1259,18 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, err =VIRTIO_CRYPTO_NOTSUPP ;break ;case VIRTIO_CRYPTO_SYM_OP_CIPHER : - err =prepare_sym_cipher_op (vcrypto, op, vc_req, +vhost_user_iotlb_rd_lock (vc_req_out->vq); + err =prepare_sym_cipher_op (vcrypto, op, vc_req_out, &req.u.sym_req.u.cipher, desc, max_n_descs); +vhost_user_iotlb_rd_unlock (vc_req_out->vq);break ;case VIRTIO_CRYPTO_SYM_OP_ALGORITHM_CHAINING : - err =prepare_sym_chain_op (vcrypto, op, vc_req, +vhost_user_iotlb_rd_lock (vc_req_out->vq); + err =prepare_sym_chain_op (vcrypto, op, vc_req_out, &req.u.sym_req.u.chain, desc, max_n_descs); +vhost_user_iotlb_rd_unlock (vc_req_out->vq);break ; }if (unlikely (err !=0 )) {
@@ -1283,7 +1289,7 @@ vhost_crypto_process_one_req(struct vhost_crypto *vcrypto, error_exit: - inhdr =reach_inhdr (vc_req, descs, max_n_descs); + inhdr =reach_inhdr (vc_req->dev, vq, descs, max_n_descs);if (likely (inhdr !=NULL )) inhdr->status = (uint8_t )err;
Signature · 1 line
2.25.1
Re: [v9 1/6] vhost: fix thread safety checks for vhost crypto data req
Quoted 9 lines · Gowrishankar Muthukrishnan
For thread safety check to succeed (as in clang), calling function should ensure
vq->iotlb_locklocked before passing vq to a function that has thread safety attribute, in vhost crypto implementation.When
vhost_crypto_data_reqis local and its vq is pointer to a locked vq, clang does not recognise this inherited lock and stops compilation. This patch explicitly usesvhost_virtqueuewhere ever required and fulfills thread safety checks.
Quoted 5 lines
Signed-off-by Gowrishankar Muthukrishnan <[email protected]>--- lib/vhost/vhost_crypto.c | 76 ++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 35 deletions(-)
Thanks for doing these changes,
Maxime