Skip to content

Commit

Permalink
cryptodev: support device independent sessions
Browse files Browse the repository at this point in the history
Change crypto device's session management to make it
device independent and simplify architecture when session
is intended to be used on more than one device.

Sessions private data is agnostic to underlying device
by adding an indirection in the sessions private data
using the crypto driver identifier.
A single session can contain indirections to multiple device types.

New function rte_cryptodev_sym_session_init has been created,
to initialize the driver private session data per driver to be
used on a same session, and rte_cryptodev_sym_session_clear
to clear this data before calling rte_cryptodev_sym_session_free.

Signed-off-by: Slawomir Mrozowicz <slawomirx.mrozowicz@intel.com>
Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Declan Doherty <declan.doherty@intel.com>
Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
  • Loading branch information
smrozowx authored and pablodelara committed Jul 6, 2017
1 parent 7c110ce commit b3bbd9e
Show file tree
Hide file tree
Showing 49 changed files with 1,315 additions and 718 deletions.
5 changes: 4 additions & 1 deletion app/test-crypto-perf/cperf.h
Expand Up @@ -41,7 +41,10 @@ struct cperf_options;
struct cperf_test_vector;
struct cperf_op_fns;

typedef void *(*cperf_constructor_t)(uint8_t dev_id, uint16_t qp_id,
typedef void *(*cperf_constructor_t)(
struct rte_mempool *sess_mp,
uint8_t dev_id,
uint16_t qp_id,
const struct cperf_options *options,
const struct cperf_test_vector *t_vec,
const struct cperf_op_fns *op_fns);
Expand Down
21 changes: 13 additions & 8 deletions app/test-crypto-perf/cperf_ops.c
Expand Up @@ -367,7 +367,8 @@ cperf_set_ops_aead(struct rte_crypto_op **ops,
}

static struct rte_cryptodev_sym_session *
cperf_create_session(uint8_t dev_id,
cperf_create_session(struct rte_mempool *sess_mp,
uint8_t dev_id,
const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
uint16_t iv_offset)
Expand All @@ -377,6 +378,7 @@ cperf_create_session(uint8_t dev_id,
struct rte_crypto_sym_xform aead_xform;
struct rte_cryptodev_sym_session *sess = NULL;

sess = rte_cryptodev_sym_session_create(sess_mp);
/*
* cipher only
*/
Expand All @@ -401,7 +403,8 @@ cperf_create_session(uint8_t dev_id,
cipher_xform.cipher.iv.length = 0;
}
/* create crypto session */
sess = rte_cryptodev_sym_session_create(dev_id, &cipher_xform);
rte_cryptodev_sym_session_init(dev_id, sess, &cipher_xform,
sess_mp);
/*
* auth only
*/
Expand All @@ -427,7 +430,8 @@ cperf_create_session(uint8_t dev_id,
auth_xform.auth.iv.length = 0;
}
/* create crypto session */
sess = rte_cryptodev_sym_session_create(dev_id, &auth_xform);
rte_cryptodev_sym_session_init(dev_id, sess, &auth_xform,
sess_mp);
/*
* cipher and auth
*/
Expand Down Expand Up @@ -483,13 +487,13 @@ cperf_create_session(uint8_t dev_id,
if (options->op_type == CPERF_CIPHER_THEN_AUTH) {
cipher_xform.next = &auth_xform;
/* create crypto session */
sess = rte_cryptodev_sym_session_create(dev_id,
&cipher_xform);
rte_cryptodev_sym_session_init(dev_id,
sess, &cipher_xform, sess_mp);
} else { /* auth then cipher */
auth_xform.next = &cipher_xform;
/* create crypto session */
sess = rte_cryptodev_sym_session_create(dev_id,
&auth_xform);
rte_cryptodev_sym_session_init(dev_id,
sess, &auth_xform, sess_mp);
}
} else { /* options->op_type == CPERF_AEAD */
aead_xform.type = RTE_CRYPTO_SYM_XFORM_AEAD;
Expand All @@ -509,7 +513,8 @@ cperf_create_session(uint8_t dev_id,
options->aead_aad_sz;

/* Create crypto session */
sess = rte_cryptodev_sym_session_create(dev_id, &aead_xform);
rte_cryptodev_sym_session_init(dev_id,
sess, &aead_xform, sess_mp);
}

return sess;
Expand Down
1 change: 1 addition & 0 deletions app/test-crypto-perf/cperf_ops.h
Expand Up @@ -41,6 +41,7 @@


typedef struct rte_cryptodev_sym_session *(*cperf_sessions_create_t)(
struct rte_mempool *sess_mp,
uint8_t dev_id, const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
uint16_t iv_offset);
Expand Down
12 changes: 8 additions & 4 deletions app/test-crypto-perf/cperf_test_latency.c
Expand Up @@ -79,8 +79,10 @@ cperf_latency_test_free(struct cperf_latency_ctx *ctx, uint32_t mbuf_nb)
uint32_t i;

if (ctx) {
if (ctx->sess)
rte_cryptodev_sym_session_free(ctx->dev_id, ctx->sess);
if (ctx->sess) {
rte_cryptodev_sym_session_clear(ctx->dev_id, ctx->sess);
rte_cryptodev_sym_session_free(ctx->sess);
}

if (ctx->mbufs_in) {
for (i = 0; i < mbuf_nb; i++)
Expand Down Expand Up @@ -191,7 +193,8 @@ cperf_mbuf_create(struct rte_mempool *mempool,
}

void *
cperf_latency_test_constructor(uint8_t dev_id, uint16_t qp_id,
cperf_latency_test_constructor(struct rte_mempool *sess_mp,
uint8_t dev_id, uint16_t qp_id,
const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
const struct cperf_op_fns *op_fns)
Expand All @@ -216,7 +219,8 @@ cperf_latency_test_constructor(uint8_t dev_id, uint16_t qp_id,
sizeof(struct rte_crypto_sym_op) +
sizeof(struct cperf_op_result *);

ctx->sess = op_fns->sess_create(dev_id, options, test_vector, iv_offset);
ctx->sess = op_fns->sess_create(sess_mp, dev_id, options, test_vector,
iv_offset);
if (ctx->sess == NULL)
goto err;

Expand Down
5 changes: 4 additions & 1 deletion app/test-crypto-perf/cperf_test_latency.h
Expand Up @@ -43,7 +43,10 @@
#include "cperf_test_vectors.h"

void *
cperf_latency_test_constructor(uint8_t dev_id, uint16_t qp_id,
cperf_latency_test_constructor(
struct rte_mempool *sess_mp,
uint8_t dev_id,
uint16_t qp_id,
const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
const struct cperf_op_fns *ops_fn);
Expand Down
12 changes: 8 additions & 4 deletions app/test-crypto-perf/cperf_test_throughput.c
Expand Up @@ -64,8 +64,10 @@ cperf_throughput_test_free(struct cperf_throughput_ctx *ctx, uint32_t mbuf_nb)
uint32_t i;

if (ctx) {
if (ctx->sess)
rte_cryptodev_sym_session_free(ctx->dev_id, ctx->sess);
if (ctx->sess) {
rte_cryptodev_sym_session_clear(ctx->dev_id, ctx->sess);
rte_cryptodev_sym_session_free(ctx->sess);
}

if (ctx->mbufs_in) {
for (i = 0; i < mbuf_nb; i++)
Expand Down Expand Up @@ -175,7 +177,8 @@ cperf_mbuf_create(struct rte_mempool *mempool,
}

void *
cperf_throughput_test_constructor(uint8_t dev_id, uint16_t qp_id,
cperf_throughput_test_constructor(struct rte_mempool *sess_mp,
uint8_t dev_id, uint16_t qp_id,
const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
const struct cperf_op_fns *op_fns)
Expand All @@ -199,7 +202,8 @@ cperf_throughput_test_constructor(uint8_t dev_id, uint16_t qp_id,
uint16_t iv_offset = sizeof(struct rte_crypto_op) +
sizeof(struct rte_crypto_sym_op);

ctx->sess = op_fns->sess_create(dev_id, options, test_vector, iv_offset);
ctx->sess = op_fns->sess_create(sess_mp, dev_id, options, test_vector,
iv_offset);
if (ctx->sess == NULL)
goto err;

Expand Down
5 changes: 4 additions & 1 deletion app/test-crypto-perf/cperf_test_throughput.h
Expand Up @@ -44,7 +44,10 @@


void *
cperf_throughput_test_constructor(uint8_t dev_id, uint16_t qp_id,
cperf_throughput_test_constructor(
struct rte_mempool *sess_mp,
uint8_t dev_id,
uint16_t qp_id,
const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
const struct cperf_op_fns *ops_fn);
Expand Down
12 changes: 8 additions & 4 deletions app/test-crypto-perf/cperf_test_verify.c
Expand Up @@ -68,8 +68,10 @@ cperf_verify_test_free(struct cperf_verify_ctx *ctx, uint32_t mbuf_nb)
uint32_t i;

if (ctx) {
if (ctx->sess)
rte_cryptodev_sym_session_free(ctx->dev_id, ctx->sess);
if (ctx->sess) {
rte_cryptodev_sym_session_clear(ctx->dev_id, ctx->sess);
rte_cryptodev_sym_session_free(ctx->sess);
}

if (ctx->mbufs_in) {
for (i = 0; i < mbuf_nb; i++)
Expand Down Expand Up @@ -179,7 +181,8 @@ cperf_mbuf_create(struct rte_mempool *mempool,
}

void *
cperf_verify_test_constructor(uint8_t dev_id, uint16_t qp_id,
cperf_verify_test_constructor(struct rte_mempool *sess_mp,
uint8_t dev_id, uint16_t qp_id,
const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
const struct cperf_op_fns *op_fns)
Expand All @@ -203,7 +206,8 @@ cperf_verify_test_constructor(uint8_t dev_id, uint16_t qp_id,
uint16_t iv_offset = sizeof(struct rte_crypto_op) +
sizeof(struct rte_crypto_sym_op);

ctx->sess = op_fns->sess_create(dev_id, options, test_vector, iv_offset);
ctx->sess = op_fns->sess_create(sess_mp, dev_id, options, test_vector,
iv_offset);
if (ctx->sess == NULL)
goto err;

Expand Down
5 changes: 4 additions & 1 deletion app/test-crypto-perf/cperf_test_verify.h
Expand Up @@ -44,7 +44,10 @@


void *
cperf_verify_test_constructor(uint8_t dev_id, uint16_t qp_id,
cperf_verify_test_constructor(
struct rte_mempool *sess_mp,
uint8_t dev_id,
uint16_t qp_id,
const struct cperf_options *options,
const struct cperf_test_vector *test_vector,
const struct cperf_op_fns *ops_fn);
Expand Down
9 changes: 5 additions & 4 deletions app/test-crypto-perf/main.c
Expand Up @@ -107,13 +107,11 @@ cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs,
uint32_t max_sess_size = 0, sess_size;

for (cdev_id = 0; cdev_id < rte_cryptodev_count(); cdev_id++) {
sess_size = sizeof(struct rte_cryptodev_sym_session) +
rte_cryptodev_get_private_session_size(cdev_id);
sess_size = rte_cryptodev_get_private_session_size(cdev_id);
if (sess_size > max_sess_size)
max_sess_size = sess_size;
}


for (i = 0; i < enabled_cdev_count &&
i < RTE_CRYPTO_MAX_DEVS; i++) {
cdev_id = enabled_cdevs[i];
Expand Down Expand Up @@ -475,7 +473,10 @@ main(int argc, char **argv)

cdev_id = enabled_cdevs[i];

ctx[cdev_id] = cperf_testmap[opts.test].constructor(cdev_id, 0,
uint8_t socket_id = rte_cryptodev_socket_id(cdev_id);

ctx[cdev_id] = cperf_testmap[opts.test].constructor(
session_pool_socket[socket_id], cdev_id, 0,
&opts, t_vec, &op_fns);
if (ctx[cdev_id] == NULL) {
RTE_LOG(ERR, USER1, "Test run constructor failed\n");
Expand Down
11 changes: 0 additions & 11 deletions doc/guides/rel_notes/deprecation.rst
Expand Up @@ -54,17 +54,6 @@ Deprecation Notices
Target release for removal of the legacy API will be defined once most
PMDs have switched to rte_flow.

* cryptodev: API changes are planned for 17.08 for the sessions management
to make it agnostic to the underlying devices, removing coupling with
crypto PMDs, so a single session can be used on multiple devices.

An API of followed functions will be changed to allow operate on multiple
devices with one session:

- ``rte_cryptodev_sym_session_create``
- ``rte_cryptodev_sym_session_free``
- ``rte_cryptodev_sym_session_pool_create``

* librte_table: The ``key_mask`` parameter will be added to all the hash tables
that currently do not have it, as well as to the hash compute function prototype.
The non-"do-sig" versions of the hash tables will be removed
Expand Down
9 changes: 9 additions & 0 deletions doc/guides/rel_notes/release_17_08.rst
Expand Up @@ -116,13 +116,19 @@ New Features
* ``dev_id`` field has been removed.
* ``driver_id`` field has been removed.
* Mempool pointer ``mp`` has been removed.
* Replaced ``private`` marker with array of pointers to private data sessions
``sess_private_data``.

* **Updated cryptodev library.**

* Added AEAD algorithm specific functions and structures, so it is not
necessary to use a combination of cipher and authentication
structures anymore.
* Added helper functions for crypto device driver identification.
* Added support for multi-device sessions, so a single session can be
used in multiple drivers.
* Added functions to initialize and free individual driver private data
with a same session.

* **Updated dpaa2_sec crypto PMD.**

Expand Down Expand Up @@ -231,6 +237,9 @@ API Changes
* ``rte_cryptodev_queue_pair_attach_sym_session()`` and
``rte_cryptodev_queue_pair_dettach_sym_session()`` functions require
the new parameter ``device id``.
* Modified parameters of ``rte_cryptodev_sym_session_create()``, to accept
``mempool``, instead of ``device id`` and ``rte_crypto_sym_xform``.
* Remove ``device id`` parameter from ``rte_cryptodev_sym_session_free()``.


ABI Changes
Expand Down
47 changes: 33 additions & 14 deletions drivers/crypto/aesni_gcm/aesni_gcm_pmd.c
Expand Up @@ -155,22 +155,37 @@ aesni_gcm_get_session(struct aesni_gcm_qp *qp, struct rte_crypto_op *op)
struct rte_crypto_sym_op *sym_op = op->sym;

if (op->sess_type == RTE_CRYPTO_OP_WITH_SESSION) {
sess = (struct aesni_gcm_session *)sym_op->session->_private;
if (likely(sym_op->session != NULL))
sess = (struct aesni_gcm_session *)
get_session_private_data(
sym_op->session,
cryptodev_driver_id);
} else {
void *_sess;
void *_sess_private_data = NULL;

if (rte_mempool_get(qp->sess_mp, &_sess))
return sess;
if (rte_mempool_get(qp->sess_mp, (void **)&_sess))
return NULL;

sess = (struct aesni_gcm_session *)
((struct rte_cryptodev_sym_session *)_sess)->_private;
if (rte_mempool_get(qp->sess_mp, (void **)&_sess_private_data))
return NULL;

if (unlikely(aesni_gcm_set_session_parameters(qp->ops, sess,
sym_op->xform) != 0)) {
sess = (struct aesni_gcm_session *)_sess_private_data;

if (unlikely(aesni_gcm_set_session_parameters(qp->ops,
sess, sym_op->xform) != 0)) {
rte_mempool_put(qp->sess_mp, _sess);
rte_mempool_put(qp->sess_mp, _sess_private_data);
sess = NULL;
}
sym_op->session = (struct rte_cryptodev_sym_session *)_sess;
set_session_private_data(sym_op->session, cryptodev_driver_id,
_sess_private_data);
}

if (unlikely(sess == NULL))
op->status = RTE_CRYPTO_OP_STATUS_INVALID_SESSION;

return sess;
}

Expand Down Expand Up @@ -370,13 +385,11 @@ process_gcm_crypto_op(struct aesni_gcm_qp *qp, struct rte_crypto_op *op,
* - Returns NULL on invalid job
*/
static void
post_process_gcm_crypto_op(struct rte_crypto_op *op)
post_process_gcm_crypto_op(struct rte_crypto_op *op,
struct aesni_gcm_session *session)
{
struct rte_mbuf *m = op->sym->m_dst ? op->sym->m_dst : op->sym->m_src;

struct aesni_gcm_session *session =
(struct aesni_gcm_session *)op->sym->session->_private;

op->status = RTE_CRYPTO_OP_STATUS_SUCCESS;

/* Verify digest if required */
Expand Down Expand Up @@ -411,19 +424,25 @@ post_process_gcm_crypto_op(struct rte_crypto_op *op)
* Process a completed GCM request
*
* @param qp Queue Pair to process
* @param op Crypto operation
* @param job JOB_AES_HMAC job
*
* @return
* - Number of processed jobs
*/
static void
handle_completed_gcm_crypto_op(struct aesni_gcm_qp *qp,
struct rte_crypto_op *op)
struct rte_crypto_op *op,
struct aesni_gcm_session *sess)
{
post_process_gcm_crypto_op(op);
post_process_gcm_crypto_op(op, sess);

/* Free session if a session-less crypto op */
if (op->sess_type == RTE_CRYPTO_OP_SESSIONLESS) {
memset(sess, 0, sizeof(struct aesni_gcm_session));
memset(op->sym->session, 0,
rte_cryptodev_get_header_session_size());
rte_mempool_put(qp->sess_mp, sess);
rte_mempool_put(qp->sess_mp, op->sym->session);
op->sym->session = NULL;
}
Expand Down Expand Up @@ -458,7 +477,7 @@ aesni_gcm_pmd_dequeue_burst(void *queue_pair,
break;
}

handle_completed_gcm_crypto_op(qp, ops[i]);
handle_completed_gcm_crypto_op(qp, ops[i], sess);
}

qp->qp_stats.dequeued_count += i;
Expand Down

0 comments on commit b3bbd9e

Please sign in to comment.