Skip to content

Commit

Permalink
security: remove private mempool usage
Browse files Browse the repository at this point in the history
As per current design, rte_security_session_create()
unnecessarily use 2 mempool objects for a single session.

To address this, the API will now take only 1 mempool
object instead of 2. With this change, the library layer
will get the object from mempool and session priv data is
stored contiguously in the same mempool object.

User need to ensure that the mempool created in application
is big enough for session private data as well. This can be
ensured if the pool is created after getting size of session
priv data using API rte_security_session_get_size().

Since set and get pkt metadata for security sessions are now
made inline for Inline crypto/proto mode, a new member fast_mdata
is added to the rte_security_session.
To access opaque data and fast_mdata will be accessed via inline
APIs which can do pointer manipulations inside library from
session_private_data pointer coming from application.

Signed-off-by: Akhil Goyal <gakhil@marvell.com>
Tested-by: Gagandeep Singh <g.singh@nxp.com>
Tested-by: David Coyle <david.coyle@intel.com>
Tested-by: Kevin O'Sullivan <kevin.osullivan@intel.com>
  • Loading branch information
Akhil Goyal committed Oct 4, 2022
1 parent 2a440d6 commit 3f3fc33
Show file tree
Hide file tree
Showing 43 changed files with 200 additions and 630 deletions.
1 change: 0 additions & 1 deletion app/test-crypto-perf/cperf.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ struct cperf_op_fns;

typedef void *(*cperf_constructor_t)(
struct rte_mempool *sess_mp,
struct rte_mempool *sess_priv_mp,
uint8_t dev_id,
uint16_t qp_id,
const struct cperf_options *options,
Expand Down
13 changes: 4 additions & 9 deletions app/test-crypto-perf/cperf_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,6 @@ cperf_set_ops_aead(struct rte_crypto_op **ops,

static void *
create_ipsec_session(struct rte_mempool *sess_mp,
struct rte_mempool *priv_mp,
uint8_t dev_id,
const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
Expand Down Expand Up @@ -753,13 +752,11 @@ create_ipsec_session(struct rte_mempool *sess_mp,
rte_cryptodev_get_sec_ctx(dev_id);

/* Create security session */
return (void *)rte_security_session_create(ctx,
&sess_conf, sess_mp, priv_mp);
return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp);
}

static void *
cperf_create_session(struct rte_mempool *sess_mp,
struct rte_mempool *priv_mp,
uint8_t dev_id,
const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
Expand Down Expand Up @@ -859,12 +856,11 @@ cperf_create_session(struct rte_mempool *sess_mp,
rte_cryptodev_get_sec_ctx(dev_id);

/* Create security session */
return (void *)rte_security_session_create(ctx,
&sess_conf, sess_mp, priv_mp);
return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp);
}

if (options->op_type == CPERF_IPSEC) {
return create_ipsec_session(sess_mp, priv_mp, dev_id,
return create_ipsec_session(sess_mp, dev_id,
options, test_vector, iv_offset);
}

Expand Down Expand Up @@ -908,8 +904,7 @@ cperf_create_session(struct rte_mempool *sess_mp,
rte_cryptodev_get_sec_ctx(dev_id);

/* Create security session */
return (void *)rte_security_session_create(ctx,
&sess_conf, sess_mp, priv_mp);
return (void *)rte_security_session_create(ctx, &sess_conf, sess_mp);
}
#endif
/*
Expand Down
1 change: 0 additions & 1 deletion app/test-crypto-perf/cperf_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

typedef void *(*cperf_sessions_create_t)(
struct rte_mempool *sess_mp,
struct rte_mempool *priv_mp,
uint8_t dev_id, const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
uint16_t iv_offset);
Expand Down
3 changes: 1 addition & 2 deletions app/test-crypto-perf/cperf_test_latency.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ cperf_latency_test_free(struct cperf_latency_ctx *ctx)

void *
cperf_latency_test_constructor(struct rte_mempool *sess_mp,
struct rte_mempool *sess_priv_mp,
uint8_t dev_id, uint16_t qp_id,
const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
Expand All @@ -81,7 +80,7 @@ cperf_latency_test_constructor(struct rte_mempool *sess_mp,
sizeof(struct rte_crypto_sym_op) +
sizeof(struct cperf_op_result *);

ctx->sess = op_fns->sess_create(sess_mp, sess_priv_mp, dev_id, options,
ctx->sess = op_fns->sess_create(sess_mp, dev_id, options,
test_vector, iv_offset);
if (ctx->sess == NULL)
goto err;
Expand Down
1 change: 0 additions & 1 deletion app/test-crypto-perf/cperf_test_latency.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
void *
cperf_latency_test_constructor(
struct rte_mempool *sess_mp,
struct rte_mempool *sess_priv_mp,
uint8_t dev_id,
uint16_t qp_id,
const struct cperf_options *options,
Expand Down
3 changes: 1 addition & 2 deletions app/test-crypto-perf/cperf_test_pmd_cyclecount.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ cperf_pmd_cyclecount_test_free(struct cperf_pmd_cyclecount_ctx *ctx)

void *
cperf_pmd_cyclecount_test_constructor(struct rte_mempool *sess_mp,
struct rte_mempool *sess_priv_mp,
uint8_t dev_id, uint16_t qp_id,
const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
Expand All @@ -115,7 +114,7 @@ cperf_pmd_cyclecount_test_constructor(struct rte_mempool *sess_mp,
uint16_t iv_offset = sizeof(struct rte_crypto_op) +
sizeof(struct rte_crypto_sym_op);

ctx->sess = op_fns->sess_create(sess_mp, sess_priv_mp, dev_id, options,
ctx->sess = op_fns->sess_create(sess_mp, dev_id, options,
test_vector, iv_offset);
if (ctx->sess == NULL)
goto err;
Expand Down
1 change: 0 additions & 1 deletion app/test-crypto-perf/cperf_test_pmd_cyclecount.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
void *
cperf_pmd_cyclecount_test_constructor(
struct rte_mempool *sess_mp,
struct rte_mempool *sess_priv_mp,
uint8_t dev_id,
uint16_t qp_id,
const struct cperf_options *options,
Expand Down
3 changes: 1 addition & 2 deletions app/test-crypto-perf/cperf_test_throughput.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ cperf_throughput_test_free(struct cperf_throughput_ctx *ctx)

void *
cperf_throughput_test_constructor(struct rte_mempool *sess_mp,
struct rte_mempool *sess_priv_mp,
uint8_t dev_id, uint16_t qp_id,
const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
Expand All @@ -85,7 +84,7 @@ cperf_throughput_test_constructor(struct rte_mempool *sess_mp,
uint16_t iv_offset = sizeof(struct rte_crypto_op) +
sizeof(struct rte_crypto_sym_op);

ctx->sess = op_fns->sess_create(sess_mp, sess_priv_mp, dev_id, options,
ctx->sess = op_fns->sess_create(sess_mp, dev_id, options,
test_vector, iv_offset);
if (ctx->sess == NULL)
goto err;
Expand Down
1 change: 0 additions & 1 deletion app/test-crypto-perf/cperf_test_throughput.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
void *
cperf_throughput_test_constructor(
struct rte_mempool *sess_mp,
struct rte_mempool *sess_priv_mp,
uint8_t dev_id,
uint16_t qp_id,
const struct cperf_options *options,
Expand Down
3 changes: 1 addition & 2 deletions app/test-crypto-perf/cperf_test_verify.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ cperf_verify_test_free(struct cperf_verify_ctx *ctx)

void *
cperf_verify_test_constructor(struct rte_mempool *sess_mp,
struct rte_mempool *sess_priv_mp,
uint8_t dev_id, uint16_t qp_id,
const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
Expand All @@ -73,7 +72,7 @@ cperf_verify_test_constructor(struct rte_mempool *sess_mp,
uint16_t iv_offset = sizeof(struct rte_crypto_op) +
sizeof(struct rte_crypto_sym_op);

ctx->sess = op_fns->sess_create(sess_mp, sess_priv_mp, dev_id, options,
ctx->sess = op_fns->sess_create(sess_mp, dev_id, options,
test_vector, iv_offset);
if (ctx->sess == NULL)
goto err;
Expand Down
1 change: 0 additions & 1 deletion app/test-crypto-perf/cperf_test_verify.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
void *
cperf_verify_test_constructor(
struct rte_mempool *sess_mp,
struct rte_mempool *sess_priv_mp,
uint8_t dev_id,
uint16_t qp_id,
const struct cperf_options *options,
Expand Down
3 changes: 0 additions & 3 deletions app/test-crypto-perf/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

static struct {
struct rte_mempool *sess_mp;
struct rte_mempool *priv_mp;
} session_pool_socket[RTE_MAX_NUMA_NODES];

const char *cperf_test_type_strs[] = {
Expand Down Expand Up @@ -115,7 +114,6 @@ fill_session_pool_socket(int32_t socket_id, uint32_t session_priv_size,
printf("Allocated pool \"%s\" on socket %d\n",
mp_name, socket_id);
session_pool_socket[socket_id].sess_mp = sess_mp;
session_pool_socket[socket_id].priv_mp = sess_mp;
}

return 0;
Expand Down Expand Up @@ -660,7 +658,6 @@ main(int argc, char **argv)

ctx[i] = cperf_testmap[opts.test].constructor(
session_pool_socket[socket_id].sess_mp,
session_pool_socket[socket_id].priv_mp,
cdev_id, qp_id,
&opts, t_vec, &op_fns);
if (ctx[i] == NULL) {
Expand Down
44 changes: 5 additions & 39 deletions app/test/test_cryptodev.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,6 @@ testsuite_setup(void)
SOCKET_ID_ANY);
TEST_ASSERT_NOT_NULL(ts_params->session_mpool,
"session mempool allocation failed");
ts_params->session_priv_mpool = rte_mempool_create(
"test_sess_mp_priv", MAX_NB_SESSIONS, session_size,
0, 0, NULL, NULL, NULL, NULL, SOCKET_ID_ANY, 0);

TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
"session mempool allocation failed");

TEST_ASSERT_SUCCESS(rte_cryptodev_configure(dev_id,
&ts_params->conf),
Expand Down Expand Up @@ -694,8 +688,6 @@ testsuite_teardown(void)
if (ts_params->session_mpool != NULL) {
rte_mempool_free(ts_params->session_mpool);
ts_params->session_mpool = NULL;
rte_mempool_free(ts_params->session_priv_mpool);
ts_params->session_priv_mpool = NULL;
}

res = rte_cryptodev_close(ts_params->valid_devs[0]);
Expand Down Expand Up @@ -8621,8 +8613,7 @@ static int test_pdcp_proto(int i, int oop, enum rte_crypto_cipher_operation opc,

/* Create security session */
ut_params->sec_session = rte_security_session_create(ctx,
&sess_conf, ts_params->session_mpool,
NULL);
&sess_conf, ts_params->session_mpool);

if (!ut_params->sec_session) {
printf("TestCase %s()-%d line %d failed %s: ",
Expand Down Expand Up @@ -8901,8 +8892,7 @@ test_pdcp_proto_SGL(int i, int oop,

/* Create security session */
ut_params->sec_session = rte_security_session_create(ctx,
&sess_conf, ts_params->session_mpool,
ts_params->session_priv_mpool);
&sess_conf, ts_params->session_mpool);

if (!ut_params->sec_session) {
printf("TestCase %s()-%d line %d failed %s: ",
Expand Down Expand Up @@ -9497,8 +9487,7 @@ test_ipsec_proto_process(const struct ipsec_test_data td[],

/* Create security session */
ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
ts_params->session_mpool,
ts_params->session_priv_mpool);
ts_params->session_mpool);

if (ut_params->sec_session == NULL)
return TEST_SKIPPED;
Expand Down Expand Up @@ -10509,8 +10498,7 @@ test_docsis_proto_uplink(const void *data)

/* Create security session */
ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
ts_params->session_mpool,
ts_params->session_priv_mpool);
ts_params->session_mpool);

if (!ut_params->sec_session) {
printf("Test function %s line %u: failed to allocate session\n",
Expand Down Expand Up @@ -10694,8 +10682,7 @@ test_docsis_proto_downlink(const void *data)

/* Create security session */
ut_params->sec_session = rte_security_session_create(ctx, &sess_conf,
ts_params->session_mpool,
ts_params->session_priv_mpool);
ts_params->session_mpool);

if (!ut_params->sec_session) {
printf("Test function %s line %u: failed to allocate session\n",
Expand Down Expand Up @@ -14976,10 +14963,6 @@ test_scheduler_attach_worker_op(void)
rte_mempool_free(ts_params->session_mpool);
ts_params->session_mpool = NULL;
}
if (ts_params->session_priv_mpool) {
rte_mempool_free(ts_params->session_priv_mpool);
ts_params->session_priv_mpool = NULL;
}

if (info.sym.max_nb_sessions != 0 &&
info.sym.max_nb_sessions < MAX_NB_SESSIONS) {
Expand All @@ -15003,23 +14986,6 @@ test_scheduler_attach_worker_op(void)
"session mempool allocation failed");
}

/*
* Create mempool with maximum number of sessions,
* to include device specific session private data
*/
if (ts_params->session_priv_mpool == NULL) {
ts_params->session_priv_mpool = rte_mempool_create(
"test_sess_mp_priv",
MAX_NB_SESSIONS,
session_size,
0, 0, NULL, NULL, NULL,
NULL, SOCKET_ID_ANY,
0);

TEST_ASSERT_NOT_NULL(ts_params->session_priv_mpool,
"session mempool allocation failed");
}

ts_params->qp_conf.mp_session = ts_params->session_mpool;

ret = rte_cryptodev_scheduler_worker_attach(sched_id,
Expand Down
7 changes: 3 additions & 4 deletions app/test/test_ipsec.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,12 @@ const struct supported_auth_algo auth_algos[] = {

static int
dummy_sec_create(void *device, struct rte_security_session_conf *conf,
struct rte_security_session *sess, struct rte_mempool *mp)
struct rte_security_session *sess)
{
RTE_SET_USED(device);
RTE_SET_USED(conf);
RTE_SET_USED(mp);
RTE_SET_USED(sess);

sess->sess_private_data = NULL;
return 0;
}

Expand Down Expand Up @@ -631,7 +630,7 @@ create_dummy_sec_session(struct ipsec_unitest_params *ut,
static struct rte_security_session_conf conf;

ut->ss[j].security.ses = rte_security_session_create(&dummy_sec_ctx,
&conf, qp->mp_session, NULL);
&conf, qp->mp_session);

if (ut->ss[j].security.ses == NULL)
return -ENOMEM;
Expand Down
Loading

0 comments on commit 3f3fc33

Please sign in to comment.