diff --git a/lib/bdev/crypto/vbdev_crypto.c b/lib/bdev/crypto/vbdev_crypto.c index 57d1d70093..76c9c7837d 100644 --- a/lib/bdev/crypto/vbdev_crypto.c +++ b/lib/bdev/crypto/vbdev_crypto.c @@ -41,6 +41,7 @@ #include +#include #include #include #include @@ -160,7 +161,8 @@ struct vbdev_crypto { static TAILQ_HEAD(, vbdev_crypto) g_vbdev_crypto = TAILQ_HEAD_INITIALIZER(g_vbdev_crypto); /* Shared mempools between all devices on this system */ -static struct rte_mempool *g_session_mp = NULL; /* session mempool */ +static struct rte_mempool *g_session_mp = NULL; +static struct rte_mempool *g_session_mp_priv = NULL; static struct spdk_mempool *g_mbuf_mp = NULL; /* mbuf mempool */ static struct rte_mempool *g_crypto_op_mp = NULL; /* crypto operations, must be rte* mempool */ @@ -239,7 +241,11 @@ create_vbdev_dev(uint8_t index, uint16_t num_lcores) } struct rte_cryptodev_qp_conf qp_conf = { - .nb_descriptors = CRYPTO_QP_DESCRIPTORS + .nb_descriptors = CRYPTO_QP_DESCRIPTORS, +#if RTE_VERSION >= RTE_VERSION_NUM(19, 02, 0, 0) + .mp_session = g_session_mp, + .mp_session_private = g_session_mp_priv, +#endif }; /* Pre-setup all pottential qpairs now and assign them in the channel @@ -248,8 +254,12 @@ create_vbdev_dev(uint8_t index, uint16_t num_lcores) * even on other queue pairs. */ for (j = 0; j < device->cdev_info.max_nb_queue_pairs; j++) { +#if RTE_VERSION >= RTE_VERSION_NUM(19, 02, 0, 0) + rc = rte_cryptodev_queue_pair_setup(cdev_id, j, &qp_conf, SOCKET_ID_ANY); +#else rc = rte_cryptodev_queue_pair_setup(cdev_id, j, &qp_conf, SOCKET_ID_ANY, - (struct rte_mempool *)g_session_mp); + g_session_mp); +#endif if (rc < 0) { SPDK_ERRLOG("Failed to setup queue pair %u on " @@ -345,10 +355,25 @@ vbdev_crypto_init_crypto_drivers(void) } cache_size = spdk_min(RTE_MEMPOOL_CACHE_MAX_SIZE, NUM_SESSIONS / 2 / num_lcores); +#if RTE_VERSION >= RTE_VERSION_NUM(19, 02, 0, 0) + g_session_mp_priv = rte_mempool_create("session_mp_priv", NUM_SESSIONS, max_sess_size, cache_size, + 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0); + if (g_session_mp_priv == NULL) { + SPDK_ERRLOG("Cannot create private session pool max size 0x%x\n", max_sess_size); + return -ENOMEM; + } + + g_session_mp = rte_cryptodev_sym_session_pool_create( + "session_mp", + NUM_SESSIONS, 0, cache_size, 0, + SOCKET_ID_ANY); +#else g_session_mp = rte_mempool_create("session_mp", NUM_SESSIONS, max_sess_size, cache_size, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0); +#endif if (g_session_mp == NULL) { SPDK_ERRLOG("Cannot create session pool max size 0x%x\n", max_sess_size); + goto error_create_session_mp; return -ENOMEM; } @@ -396,6 +421,11 @@ error_create_op: error_create_mbuf: rte_mempool_free(g_session_mp); g_session_mp = NULL; +error_create_session_mp: + if (g_session_mp_priv != NULL) { + rte_mempool_free(g_session_mp_priv); + g_session_mp_priv = NULL; + } return rc; } @@ -1344,6 +1374,9 @@ vbdev_crypto_finish(void) rte_mempool_free(g_crypto_op_mp); spdk_mempool_free(g_mbuf_mp); rte_mempool_free(g_session_mp); + if (g_session_mp_priv != NULL) { + rte_mempool_free(g_session_mp_priv); + } } /* During init we'll be asked how much memory we'd like passed to us @@ -1549,7 +1582,7 @@ vbdev_crypto_claim(struct spdk_bdev *bdev) vbdev->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; rc = rte_cryptodev_sym_session_init(device->cdev_id, vbdev->session_encrypt, &vbdev->cipher_xform, - g_session_mp); + g_session_mp_priv ? g_session_mp_priv : g_session_mp); if (rc < 0) { SPDK_ERRLOG("ERROR trying to init encrypt session!\n"); rc = -EINVAL; @@ -1559,7 +1592,7 @@ vbdev_crypto_claim(struct spdk_bdev *bdev) vbdev->cipher_xform.cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; rc = rte_cryptodev_sym_session_init(device->cdev_id, vbdev->session_decrypt, &vbdev->cipher_xform, - g_session_mp); + g_session_mp_priv ? g_session_mp_priv : g_session_mp); if (rc < 0) { SPDK_ERRLOG("ERROR trying to init decrypt session!\n"); rc = -EINVAL; diff --git a/test/unit/lib/bdev/crypto.c/crypto_ut.c b/test/unit/lib/bdev/crypto.c/crypto_ut.c index 59c9a8565f..6cec0d5369 100644 --- a/test/unit/lib/bdev/crypto.c/crypto_ut.c +++ b/test/unit/lib/bdev/crypto.c/crypto_ut.c @@ -182,9 +182,18 @@ DEFINE_STUB(rte_crypto_op_pool_create, struct rte_mempool *, unsigned cache_size, uint16_t priv_size, int socket_id), (struct rte_mempool *)1); DEFINE_STUB(rte_cryptodev_device_count_by_driver, uint8_t, (uint8_t driver_id), 0); DEFINE_STUB(rte_cryptodev_configure, int, (uint8_t dev_id, struct rte_cryptodev_config *config), 0); +#if RTE_VERSION >= RTE_VERSION_NUM(19, 02, 0, 0) +DEFINE_STUB(rte_cryptodev_queue_pair_setup, int, (uint8_t dev_id, uint16_t queue_pair_id, + const struct rte_cryptodev_qp_conf *qp_conf, int socket_id), 0); +DEFINE_STUB(rte_cryptodev_sym_session_pool_create, struct rte_mempool *, (const char *name, + uint32_t nb_elts, + uint32_t elt_size, uint32_t cache_size, uint16_t priv_size, + int socket_id), (struct rte_mempool *)1); +#else DEFINE_STUB(rte_cryptodev_queue_pair_setup, int, (uint8_t dev_id, uint16_t queue_pair_id, const struct rte_cryptodev_qp_conf *qp_conf, int socket_id, struct rte_mempool *session_pool), 0); +#endif DEFINE_STUB(rte_cryptodev_start, int, (uint8_t dev_id), 0); DEFINE_STUB_V(rte_cryptodev_stop, (uint8_t dev_id)); DEFINE_STUB(rte_cryptodev_sym_session_create, struct rte_cryptodev_sym_session *, @@ -692,6 +701,7 @@ test_initdrivers(void) int rc; static struct spdk_mempool *orig_mbuf_mp; static struct rte_mempool *orig_session_mp; + static struct rte_mempool *orig_session_mp_priv; /* These tests will alloc and free our g_mbuf_mp @@ -699,7 +709,9 @@ test_initdrivers(void) */ orig_mbuf_mp = g_mbuf_mp; orig_session_mp = g_session_mp; + orig_session_mp_priv = g_session_mp_priv; + g_session_mp_priv = NULL; g_session_mp = NULL; g_mbuf_mp = NULL; @@ -710,6 +722,7 @@ test_initdrivers(void) CU_ASSERT(rc == 0); CU_ASSERT(g_mbuf_mp == NULL); CU_ASSERT(g_session_mp == NULL); + CU_ASSERT(g_session_mp_priv == NULL); /* Test failure of DPDK dev init. */ MOCK_SET(rte_cryptodev_count, 2); @@ -718,6 +731,7 @@ test_initdrivers(void) CU_ASSERT(rc == -EINVAL); CU_ASSERT(g_mbuf_mp == NULL); CU_ASSERT(g_session_mp == NULL); + CU_ASSERT(g_session_mp_priv == NULL); MOCK_SET(rte_vdev_init, 0); /* Can't create session pool. */ @@ -726,6 +740,7 @@ test_initdrivers(void) CU_ASSERT(rc == -ENOMEM); CU_ASSERT(g_mbuf_mp == NULL); CU_ASSERT(g_session_mp == NULL); + CU_ASSERT(g_session_mp_priv == NULL); MOCK_CLEAR(spdk_mempool_create); /* Can't create op pool. */ @@ -734,6 +749,7 @@ test_initdrivers(void) CU_ASSERT(rc == -ENOMEM); CU_ASSERT(g_mbuf_mp == NULL); CU_ASSERT(g_session_mp == NULL); + CU_ASSERT(g_session_mp_priv == NULL); MOCK_SET(rte_crypto_op_pool_create, (struct rte_mempool *)1); /* Check resources are not sufficient */ @@ -750,6 +766,7 @@ test_initdrivers(void) MOCK_SET(rte_cryptodev_configure, 0); CU_ASSERT(g_mbuf_mp == NULL); CU_ASSERT(g_session_mp == NULL); + CU_ASSERT(g_session_mp_priv == NULL); CU_ASSERT(rc == -EINVAL); /* Test failure of qp setup. */ @@ -759,6 +776,7 @@ test_initdrivers(void) CU_ASSERT(rc == -EINVAL); CU_ASSERT(g_mbuf_mp == NULL); CU_ASSERT(g_session_mp == NULL); + CU_ASSERT(g_session_mp_priv == NULL); MOCK_SET(rte_cryptodev_queue_pair_setup, 0); /* Test failure of dev start. */ @@ -768,6 +786,7 @@ test_initdrivers(void) CU_ASSERT(rc == -EINVAL); CU_ASSERT(g_mbuf_mp == NULL); CU_ASSERT(g_session_mp == NULL); + CU_ASSERT(g_session_mp_priv == NULL); MOCK_SET(rte_cryptodev_start, 0); /* Test happy path. */ @@ -778,11 +797,16 @@ test_initdrivers(void) CU_ASSERT(g_session_mp != NULL); spdk_mempool_free(g_mbuf_mp); rte_mempool_free(g_session_mp); + if (g_session_mp_priv != NULL) { + /* g_session_mp_priv may or may not be set depending on the DPDK version */ + rte_mempool_free(g_session_mp_priv); + } CU_ASSERT(rc == 0); /* restore our initial values. */ g_mbuf_mp = orig_mbuf_mp; g_session_mp = orig_session_mp; + g_session_mp_priv = orig_session_mp_priv; } static void