bdev/crypto: compile with DPDK 19.02

It seems like DPDK 19.02 has split the "session mempool"
into two separate mempools but this isn't really described
in the DPDK release notes, so this patch only makes our
crypto code behave just like DPDK crypto examples.

rte_cryptodev_queue_pair_setup() no longer accepts
a separate mempool parameter but instead requires it
to be passed through a new field in struct
rte_cryptodev_qp_conf, which is also passed as a param
to rte_cryptodev_queue_pair_setup(). It's referred to as
"session private mempool" instead of "session mempool",
which makes some sense since we already use
rte_cryptodev_sym_get_private_session_size() (with the
word "private" in name) to calculate its size.

The other mempool - "session mempool" - now has to be
allocated with rte_cryptodev_sym_session_pool_create()
instead of regular rte_mempool_create().

Change-Id: I3bc6185855988b864ca59bc1972beaf4f7ea8925
Signed-off-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-on: https://review.gerrithub.io/c/443738
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Darek Stojaczyk 2019-02-07 11:38:34 +01:00 committed by Jim Harris
parent b38e3a60c6
commit 5c1c946c7a
2 changed files with 62 additions and 5 deletions

View File

@ -41,6 +41,7 @@
#include <rte_config.h>
#include <rte_version.h>
#include <rte_bus_vdev.h>
#include <rte_crypto.h>
#include <rte_cryptodev.h>
@ -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;

View File

@ -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