From patchwork Wed Jul 15 15:50:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arkadiusz Kusztal X-Patchwork-Id: 74120 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 223D9A0547; Wed, 15 Jul 2020 17:51:30 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 07BEA1BEA8; Wed, 15 Jul 2020 17:51:00 +0200 (CEST) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 52DCE1BE95 for ; Wed, 15 Jul 2020 17:50:58 +0200 (CEST) IronPort-SDR: 1j9gUlufFT4pHPZMDK2ZYFY6aPnsxfZHlsrBp7LH1bBYkzQbffdCd9mk6konnxi2y1NtNlzp94 3MDJZxlPZlpQ== X-IronPort-AV: E=McAfee;i="6000,8403,9683"; a="167303567" X-IronPort-AV: E=Sophos;i="5.75,355,1589266800"; d="scan'208";a="167303567" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jul 2020 08:50:57 -0700 IronPort-SDR: xHYpfOBK9Qivgac0/igyDY6zDp6X1hDfCKH9oGfD4Wm6JWDy3p67Sjw6zzaxP119v09L3MenwM bnukPGMTzJHg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,355,1589266800"; d="scan'208";a="318102552" Received: from akusztax-mobl.ger.corp.intel.com ([10.104.121.32]) by fmsmga002.fm.intel.com with ESMTP; 15 Jul 2020 08:50:55 -0700 From: Arek Kusztal To: dev@dpdk.org Cc: akhil.goyal@nxp.com, fiona.trahe@intel.com, Arek Kusztal Date: Wed, 15 Jul 2020 17:50:42 +0200 Message-Id: <20200715155043.12476-5-arkadiuszx.kusztal@intel.com> X-Mailer: git-send-email 2.19.1.windows.1 In-Reply-To: <20200715155043.12476-1-arkadiuszx.kusztal@intel.com> References: <20200715155043.12476-1-arkadiuszx.kusztal@intel.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 4/5] app/mp_crypto: add enqueue-dequeue functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Add enqueue/dequeue functions and related dependency functions to multi process crypto app. Command line options to use are described in mp_crypto.rst file. Signed-off-by: Arek Kusztal --- app/test-mp-crypto/Makefile | 2 +- app/test-mp-crypto/main.c | 544 +++++++++++++++++++++++++++++++++ app/test-mp-crypto/meson.build | 3 +- app/test-mp-crypto/mp_crypto.c | 91 ++++++ app/test-mp-crypto/mp_crypto.h | 27 ++ app/test-mp-crypto/mp_crypto_vectors.c | 174 +++++++++++ app/test-mp-crypto/mp_crypto_vectors.h | 66 ++++ 7 files changed, 905 insertions(+), 2 deletions(-) create mode 100644 app/test-mp-crypto/mp_crypto_vectors.c create mode 100644 app/test-mp-crypto/mp_crypto_vectors.h diff --git a/app/test-mp-crypto/Makefile b/app/test-mp-crypto/Makefile index 9fc1f3c..5d59503 100644 --- a/app/test-mp-crypto/Makefile +++ b/app/test-mp-crypto/Makefile @@ -10,6 +10,6 @@ CFLAGS += $(WERROR_FLAGS) CFLAGS += -O3 # all source are stored in SRCS-y -SRCS-y := main.c mp_crypto.c mp_crypto_parser.c mp_crypto_ipc.c +SRCS-y := main.c mp_crypto.c mp_crypto_parser.c mp_crypto_ipc.c mp_crypto_vectors.c include $(RTE_SDK)/mk/rte.app.mk diff --git a/app/test-mp-crypto/main.c b/app/test-mp-crypto/main.c index 46c8055..25833d6 100644 --- a/app/test-mp-crypto/main.c +++ b/app/test-mp-crypto/main.c @@ -562,6 +562,533 @@ int mp_crypto_setup_mpool(void) return 0; } +static int check_capabilities(int dev_id, + const struct mp_crypto_session_vector *vector) +{ + struct rte_cryptodev_sym_capability_idx cap_idx; + + cap_idx.type = vector->x_type; + if (vector->x_type == RTE_CRYPTO_SYM_XFORM_AEAD) + cap_idx.algo.aead = vector->aead_algo; + + /* For now rescricted only to AEAD */ + + if (rte_cryptodev_sym_capability_get(dev_id, &cap_idx) == NULL) + return -ENOTSUP; + + return 0; +} + +int +mp_crypto_init_sessions(void) +{ + uint64_t session_mask_id; + uint64_t session_id; + int i; + int capabiliy_checked = 1; + /* Check if all devices support vector 0 */ + for (i = 0; i < MP_APP_MAX_VECTORS; i++) { + int dev_id = mp_app_devs[i].id; + /* TODO use proper vector(s), not hardcoded one */ + if (dev_id < 0) + continue; + + int k = 0; + + while (mp_app_params->enq_param.vector_number[k] >= 0 && + k < MP_APP_MAX_VECTORS) { + int vector_number = + mp_app_params->enq_param.vector_number[k]; + + if (vector_number >= (int)mp_app_numof_ops) { + MP_APP_LOG(ERR, COL_RED, + "Not recognized test vector %d", + vector_number); + return -1; + } + if (check_capabilities(dev_id, + &session_vectors[vectors[ + vector_number].session])) { + MP_APP_LOG(ERR, COL_RED, + "Algorithm unsupported on dev %d", + dev_id); + capabiliy_checked = 0; + } + k++; + } + } + if (capabiliy_checked == 0) + return -1; + + for (session_mask_id = 1, session_id = 0; + session_id <= mp_app_numof_sessions; + session_mask_id <<= 1, session_id++) { + + if (session_mask_id & mp_app_params->session_mask) { + struct rte_cryptodev_sym_session *sess = + mp_app_create_session(mp_app_device_id, + &session_vectors[session_id]); + if (sess == NULL) { + MP_APP_LOG(ERR, COL_RED, + "Error when creating session = %p", + sess); + return -1; + } + rte_spinlock_lock(&mp_shared_data->sessions.lock); + int clear_session = 1; + + if (mp_shared_data->sessions.sym_sessions[ + session_id].session + == NULL) { + mp_shared_data->sessions.sym_sessions[ + session_id].session + = sess; + clear_session = 0; + MP_APP_LOG(INFO, COL_BLUE, + "Initialized session = %"PRIu64, + session_id); + } else { + /* Actually refcnt should be incremented + * on demand mp_shared_data->sessions. + * sym_sessions [session_id].refcnt++; + */ + } + rte_spinlock_unlock(&mp_shared_data->sessions.lock); + if (clear_session) + rte_cryptodev_sym_session_free(sess); + } + } + return 0; +} + +static void +setup_ops_main_loop(int session_id, int vector_number) +{ + while (1) { + rte_spinlock_lock(&mp_shared_data->sessions.lock); + if (mp_shared_data->sessions.sym_sessions[ + session_id].session + != NULL) { + mp_shared_data->sessions.sym_sessions[ + session_id].refcnt++; + rte_spinlock_unlock(&mp_shared_data->sessions.lock); + return; + } + rte_spinlock_unlock(&mp_shared_data->sessions.lock); + + MP_APP_LOG(WARNING, COL_YEL, + "Session %d was not yet created, vector %d", + session_id, vector_number); + char c; + + MP_APP_LOG(INFO, COL_NORM, + "Session %d not yet created.\n - Press 'w' to wait until other process will create it\n - Press 'n' to create local session", + vectors[session_id].session); + int __rte_unused r = scanf("%c", &c); + + if (c == 'n') { + struct rte_cryptodev_sym_session *sess = + mp_app_create_session( + mp_app_device_id, + &session_vectors[session_id]); + mp_crypto_local_sessions[session_id] = + sess; + return; + } else if (c == 'w') { + int timeout = 3; + int counter = 1; + + while (counter <= timeout) { + rte_delay_ms(1000); + MP_APP_LOG(INFO, COL_NORM, + "Waiting for %d out of %d seconds", + counter++, timeout); + } + } + } +} + +int mp_crypto_setup_ops(void) +{ + int i; + int used_vectors = 0; + int selected_vectors[MP_APP_MAX_VECTORS]; + + for (i = 0; i < MP_APP_MAX_VECTORS; i++) + selected_vectors[i] = -1; + + i = 0; + while (mp_app_params->enq_param.vector_number[i] >= 0 && + i < MP_APP_MAX_VECTORS) { + int vector_number = mp_app_params->enq_param.vector_number[i]; + + if (mp_app_params->enq_param.vector_number[i] >= + (int)mp_app_numof_ops) { + MP_APP_LOG(ERR, COL_RED, + "Crypto vector %d not defined, skipping", + mp_app_params->enq_param.vector_number[i]); + i++; + continue; + } + /* Aquire session */ + int session_id = vectors[vector_number].session; + + setup_ops_main_loop(vectors[vector_number].session, + vector_number); + MP_APP_LOG(INFO, COL_BLUE, + "Configuring vector %d, using session %d", + vector_number, session_id); + + selected_vectors[used_vectors++] = vector_number; + i++; + } + + if (used_vectors == 0) + return 0; + + int curr_vector = 0; + /* Create vectors and attach to sessions */ + + for (i = 0; i < MP_CRYPTO_QP_DESC_NUM; i++) { + int session_id = + vectors[selected_vectors[curr_vector]].session; + if (mp_crypto_local_sessions[session_id] != NULL) { + mp_crypto_create_op(mp_crypto_ops[i], + mp_crypto_mbufs[i], + selected_vectors[curr_vector], + mp_crypto_local_sessions[session_id]); + } else { + mp_crypto_create_op(mp_crypto_ops[i], + mp_crypto_mbufs[i], + selected_vectors[curr_vector], + mp_shared_data->sessions.sym_sessions + [session_id].session); + } + } + return 0; +} + +static int check_for_queue(int dev_id, int qp_id) +{ + int ret = rte_cryptodev_get_qp_status(dev_id, qp_id); + + if (ret <= 0) { + MP_APP_LOG(WARNING, COL_YEL, + "Queue %d on dev %d not initialized", + qp_id, dev_id); + printf( + "\n - Press 'w' to wait until other process will initialize it"); + printf("\n - Press 'x' to exit"); + char c; + int __rte_unused r = scanf("%s", &c); + + if (c == 'w') { + int timeout = 3; + int counter = 1; + + while (counter <= timeout) { + rte_delay_ms(1000); + MP_APP_LOG(INFO, COL_NORM, + "Waiting for %d out of %d seconds", + counter++, 3); + } + return -1; + } else if (c == 'x') + return -2; + else + return -2; + } + return 0; +} + +static void enqueue(int enq_dev_id, int enq_qp_id, uint64_t *enqueued, + uint64_t pcks_to_enq, uint64_t *curr_offset_enq, + int *enq_livesign, int process_enq, int process_deq, + int *livesign_print_idx, int *livesign_deq_print_idx) +{ + if (*enqueued < pcks_to_enq || pcks_to_enq == 0) { + /* Consider clearing param above */ + uint64_t enq; + uint64_t to_enq = (MP_CRYPTO_QP_DESC_NUM - + *curr_offset_enq) > MP_CRYPTO_BURST_NUM ? + MP_CRYPTO_BURST_NUM : MP_CRYPTO_QP_DESC_NUM + - *curr_offset_enq; + + if (pcks_to_enq && to_enq > pcks_to_enq - *enqueued) + to_enq = pcks_to_enq - *enqueued; + enq = rte_cryptodev_enqueue_burst(enq_dev_id, + enq_qp_id, &mp_crypto_ops[*curr_offset_enq], + to_enq); + + *enqueued += enq; + *enq_livesign += enq; + *curr_offset_enq = *enqueued % MP_CRYPTO_QP_DESC_NUM; + if (*enq_livesign > mp_app_params->enq_param.checkpoint) { + + if (process_enq && !process_deq) { + MP_APP_LOG_NO_RET(INFO, COL_NORM, + "Enqueuing %c", + livesign_print_char[*livesign_print_idx]); + } + if (process_enq && process_deq) { + MP_APP_LOG_NO_RET(INFO, COL_NORM, + "Enqueuing %c Dequeueing %c", + livesign_print_char[*livesign_print_idx], + livesign_print_char[*livesign_deq_print_idx]); + } + + (*livesign_print_idx)++; + *livesign_print_idx = *livesign_print_idx % 4; + *enq_livesign = 0; + } + } +} + +static int dequeue(int deq_dev_id, int deq_qp_id, uint64_t *dequeued, + uint64_t pcks_to_deq, uint64_t *curr_offset_deq, + int *deq_livesign, int process_enq, int process_deq, + int *livesign_print_idx, int *livesign_deq_print_idx, + int64_t *deq_stall_counter, uint64_t *deq_threshold) +{ + if (*dequeued < pcks_to_deq || pcks_to_deq == 0) { + uint64_t deq; + uint64_t to_deq = (MP_CRYPTO_QP_DESC_NUM - + *curr_offset_deq) + > MP_CRYPTO_BURST_NUM ? MP_CRYPTO_BURST_NUM : + MP_CRYPTO_QP_DESC_NUM - *curr_offset_deq; + + if (pcks_to_deq && to_deq > pcks_to_deq - *dequeued) + to_deq = pcks_to_deq - *dequeued; + deq = rte_cryptodev_dequeue_burst(deq_dev_id, + deq_qp_id, &mp_crypto_ops_ret[*curr_offset_deq], + to_deq); + *dequeued += deq; + *deq_livesign += deq; + *curr_offset_deq = *dequeued % MP_CRYPTO_QP_DESC_NUM; + if (*deq_livesign > mp_app_params->deq_param.checkpoint) { + if (process_deq && !process_enq) { + MP_APP_LOG_NO_RET(INFO, COL_NORM, + "Dequeueing %c", + livesign_print_char[*livesign_deq_print_idx]); + } + if (process_enq && process_deq) { + MP_APP_LOG_NO_RET(INFO, COL_NORM, + "Enqueuing %c Dequeueing %c", + livesign_print_char[*livesign_print_idx], + livesign_print_char[*livesign_deq_print_idx]); + } + (*livesign_deq_print_idx)++; + *livesign_deq_print_idx %= 4; + *deq_livesign = 0; + } + if (deq == 0) + (*deq_stall_counter)++; + else + *deq_stall_counter = 0; + if (mp_crypto_exit_flag) { + *deq_threshold += deq; + if (*deq_threshold > DEQ_THRESHOLD) + return -1; + if (*deq_stall_counter > DEQ_THRESHOLD) + return -1; + } + } + return 0; +} + +int mp_crypto_flow(void) +{ + int process_enq = 0, process_deq = 0; + uint64_t curr_offset_enq = 0; + uint64_t curr_offset_deq = 0; + uint64_t enqueued = 0; + uint64_t dequeued = 0; + uint64_t deq_threshold = 0; + char c = 0; + uint64_t pcks_to_enq = 0, pcks_to_deq = 0; + + int enq_dev_id = mp_app_devs[mp_app_params->enq_param.dev_id].id; + int deq_dev_id = mp_app_devs[mp_app_params->deq_param.dev_id].id; + int enq_qp_id = mp_app_params->enq_param.qp_id; + int deq_qp_id = mp_app_params->deq_param.qp_id; + int enq_livesign = 0, deq_livesign = 0; + int64_t deq_stall_counter = 0; + int livesign_print_idx = 0; + int livesign_deq_print_idx = 0; + + if (mp_app_params->enq_param.dev_id >= 0 && + !mp_app_devs[mp_app_params->enq_param.dev_id].probed) { + MP_APP_LOG(ERR, COL_RED, "Incorrect enq device provided %d", + mp_app_params->enq_param.dev_id); + } else if (mp_app_params->enq_param.dev_id >= 0) { + MP_APP_LOG(INFO, COL_BLUE, + "Start enqueuing packets on dev %d qp %d", + mp_app_params->enq_param.dev_id, + mp_app_params->enq_param.qp_id); + pcks_to_enq = mp_app_params->enq_param.ops_no; + process_enq = 1; + } + if (mp_app_params->deq_param.dev_id >= 0 && + !mp_app_devs[mp_app_params->deq_param.dev_id].probed) { + MP_APP_LOG(ERR, COL_RED, "Incorrect deq device provided %d", + mp_app_params->deq_param.dev_id); + } else if (mp_app_params->deq_param.dev_id >= 0) { + MP_APP_LOG(INFO, COL_BLUE, + "Start dequeuing packets on dev %d qp %d", + mp_app_params->deq_param.dev_id, + mp_app_params->deq_param.qp_id); + pcks_to_deq = mp_app_params->deq_param.ops_no; + process_deq = 1; + } + + if (process_enq == 0 && process_deq == 0) { + MP_APP_LOG_2(WARNING, COL_YEL, "Nothing to process"); + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + while (c != 'k') { + printf("\nPress 'k' to exit: "); + int __rte_unused r = scanf("%c", &c); + } + } + return 0; + } + + /* Check if enq queue was configured */ + while (process_enq) { + int v = check_for_queue(enq_dev_id, enq_qp_id); + + if (v == -1) + continue; + else if (v == 0) + break; + else + return -1; + } + + /* Check if deq queue was configured */ + while (process_deq) { + int v = check_for_queue(deq_dev_id, deq_qp_id); + + if (v == -1) + continue; + else if (v == 0) + break; + else + return -1; + } + + if (process_enq && !process_deq) { + MP_APP_LOG_NO_RET(INFO, COL_NORM, "Enqueuing %c", + livesign_print_char[livesign_print_idx]); + } else if (process_deq && !process_enq) { + MP_APP_LOG_NO_RET(INFO, COL_NORM, "Dequeuing %c", + livesign_print_char[livesign_deq_print_idx]); + } else if (process_enq && process_deq) { + MP_APP_LOG_NO_RET(INFO, COL_NORM, "Enqueuing %c Dequeueing %c", + livesign_print_char[livesign_print_idx], + livesign_print_char[livesign_deq_print_idx]); + } + while (1) { + if (process_enq && !mp_crypto_exit_flag) { + enqueue(enq_dev_id, enq_qp_id, &enqueued, + pcks_to_enq, &curr_offset_enq, + &enq_livesign, process_enq, process_deq, + &livesign_print_idx, &livesign_deq_print_idx); + } + + if (process_deq) { + int ret = dequeue(deq_dev_id, deq_qp_id, &dequeued, + pcks_to_deq, &curr_offset_deq, + &deq_livesign, process_enq, process_deq, + &livesign_print_idx, &livesign_deq_print_idx, + &deq_stall_counter, &deq_threshold); + + if (ret < 0) + break; + } + + if (((dequeued == pcks_to_deq && process_deq)) && + ((enqueued == pcks_to_enq && process_enq))) { + MP_APP_LOG(INFO, COL_GREEN, + "\nEnqueued %"PRIu64", dequeued %"PRIu64" packets", + enqueued, dequeued); + break; + } else if (dequeued == pcks_to_deq && process_deq && + !process_enq && pcks_to_deq) { + MP_APP_LOG(INFO, COL_GREEN, "\nDequeued %"PRIu64" packets", + dequeued); + break; + } else if (enqueued == pcks_to_enq && process_enq && + !process_deq && process_enq) { + MP_APP_LOG(INFO, COL_GREEN, "\nEnqueued %"PRIu64" packets", + enqueued); + break; + } + if (mp_crypto_exit_flag && !process_deq) + break; + } + + /* Verify if all packets are correct */ + if (process_deq) { + uint64_t last_packet = pcks_to_deq > MP_CRYPTO_QP_DESC_NUM ? + MP_CRYPTO_QP_DESC_NUM : pcks_to_deq; + if (pcks_to_deq == 0) + last_packet = MP_CRYPTO_QP_DESC_NUM; + if (last_packet >= dequeued) + last_packet = dequeued; + uint64_t k; + int err = 0; + + for (k = 0; k < last_packet; k++) { + if (mp_crypto_ops_ret[k]->status != + RTE_CRYPTO_OP_STATUS_SUCCESS) { + MP_APP_LOG(ERR, COL_RED, + "error when checking status of %"PRIu64" packet out of last %"PRIu64" packets", + k, last_packet); + err = 1; + break; + } + } + if (err == 0) { + MP_APP_LOG(INFO, COL_GREEN, + "\nAll %"PRIu64" last packets verified correctly", + last_packet); + } + } + + if (mp_app_params->print_stats) { + struct rte_cryptodev_stats stats; + + if (enq_qp_id >= 0) { + rte_cryptodev_stats_get(enq_dev_id, &stats); + MP_APP_LOG(INFO, COL_BLUE, + "STATS: Enqueued on dev %d = %"PRIu64, + enq_dev_id, stats.enqueued_count); + MP_APP_LOG(INFO, COL_BLUE, + "STATS: Enqueue err count on dev %d = %"PRIu64, + enq_dev_id, + stats.enqueue_err_count); + } + if (deq_qp_id >= 0) { + rte_cryptodev_stats_get(deq_dev_id, &stats); + MP_APP_LOG(INFO, COL_BLUE, + "STATS: Dequeued on dev %d = %"PRIu64, + deq_dev_id, stats.dequeued_count); + MP_APP_LOG(INFO, COL_BLUE, + "STATS: Dequeue err count on dev %d = %"PRIu64, + deq_dev_id, stats.dequeue_err_count); + } + + if (rte_eal_process_type() == RTE_PROC_PRIMARY) { + while (c != 'k') { + printf("\nPress 'k' to exit: "); + int __rte_unused r = scanf("%c", &c); + } + } + } + + return 0; +} + int main(int argc, char *argv[]) { @@ -587,6 +1114,23 @@ int main(int argc, char *argv[]) MP_APP_LOG_2(ERR, COL_RED, "Cannot create mempools"); goto err; } + ret = mp_crypto_init_sessions(); + if (ret < 0) { + MP_APP_LOG_2(ERR, COL_RED, "Cannot initialize sessions"); + goto err; + } + + ret = mp_crypto_setup_ops(); + if (ret < 0) { + MP_APP_LOG_2(ERR, COL_RED, "Cannot setup ops"); + goto err; + } + + ret = mp_crypto_flow(); + if (ret < 0) { + MP_APP_LOG_2(ERR, COL_RED, "Cannot enq/deq"); + goto err; + } mp_crypto_exit_app(); return 0; diff --git a/app/test-mp-crypto/meson.build b/app/test-mp-crypto/meson.build index 12a6d49..885668b 100644 --- a/app/test-mp-crypto/meson.build +++ b/app/test-mp-crypto/meson.build @@ -1,7 +1,8 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2020 Intel Corporation -sources = files('mp_crypto.c', +sources = files('mp_crypto_vectors.c', + 'mp_crypto.c', 'mp_crypto_parser.c', 'mp_crypto_ipc.c', 'main.c') diff --git a/app/test-mp-crypto/mp_crypto.c b/app/test-mp-crypto/mp_crypto.c index b996cf5..efa2634 100644 --- a/app/test-mp-crypto/mp_crypto.c +++ b/app/test-mp-crypto/mp_crypto.c @@ -43,3 +43,94 @@ struct rte_crypto_op *mp_crypto_ops_ret[MP_CRYPTO_OPS_NUM]; /* Per process set of return rte crypto ops */ struct rte_mbuf *mp_crypto_mbufs[MP_CRYPTO_OPS_NUM]; /* Per process set of rte mbufs */ +struct rte_cryptodev_sym_session *mp_crypto_local_sessions[MAX_NUM_OF_SESSIONS]; +/* Array of private sessions */ + +/* Function for creating sessions */ +struct rte_cryptodev_sym_session *mp_app_create_session + (int dev_id, const struct mp_crypto_session_vector *vector) +{ + if (vector->x_type == RTE_CRYPTO_SYM_XFORM_AEAD) + return mp_app_create_aead_session(dev_id, vector); + MP_APP_LOG_2(ERR, COL_RED, "Invalid xform type"); + return NULL; +} + +/* Create AEAD session */ +struct rte_cryptodev_sym_session* +mp_app_create_aead_session(int dev_id, + const struct mp_crypto_session_vector *vector) +{ + struct rte_cryptodev_sym_session *session; + struct rte_crypto_sym_xform xform; + + xform.next = NULL; + xform.type = RTE_CRYPTO_SYM_XFORM_AEAD; + xform.aead.key.length = vector->crypto_key.len; + xform.aead.key.data = vector->crypto_key.data; + xform.aead.algo = vector->aead_algo; + xform.aead.digest_length = vector->digest_len; + xform.aead.iv.length = vector->iv_len; + xform.aead.iv.offset = IV_OFFSET; + xform.aead.aad_length = vector->aad_len; + xform.aead.op = RTE_CRYPTO_AEAD_OP_ENCRYPT; + + session = rte_cryptodev_sym_session_create(mp_crypto_session_mempool); + if (session == NULL) { + MP_APP_LOG_2(ERR, COL_RED, "Failed to create session"); + return NULL; + } + int status = rte_cryptodev_sym_session_init(dev_id, session, + &xform, mp_crypto_priv_session_mp); + if (status < 0) { + MP_APP_LOG_2(ERR, COL_RED, "Failed to init session"); + return NULL; + } + + return session; +} + +int +mp_crypto_create_op(struct rte_crypto_op *op, struct rte_mbuf *mbuf, + uint16_t vector_number, + struct rte_cryptodev_sym_session *sess) +{ + uint8_t *plaintext; + uint32_t aad_pad_len = + RTE_ALIGN_CEIL(session_vectors[vectors[vector_number]. + session].aad_len, 16); + + memset(rte_pktmbuf_mtod(mbuf, uint8_t *), 0, + rte_pktmbuf_tailroom(mbuf)); + struct rte_crypto_sym_op *sym_op = op->sym; + + sym_op->aead.aad.data = (uint8_t *)rte_pktmbuf_append(mbuf, + aad_pad_len); + sym_op->aead.aad.phys_addr = + rte_pktmbuf_iova(mbuf); + memcpy(sym_op->aead.aad.data, vectors[vector_number].aad.data, + session_vectors[vectors[vector_number].session].aad_len); + uint8_t *iv_ptr = rte_crypto_op_ctod_offset(op, + uint8_t *, IV_OFFSET); + rte_memcpy(iv_ptr, vectors[vector_number].iv, + session_vectors[vectors[vector_number].session].iv_len); + + plaintext = (uint8_t *)rte_pktmbuf_append(mbuf, + vectors[vector_number].plaintext.len); + rte_memcpy(plaintext, vectors[vector_number].plaintext.data, + vectors[vector_number].plaintext.len); + + sym_op->aead.digest.phys_addr = + rte_pktmbuf_iova_offset(mbuf, + vectors[vector_number].plaintext.len); + + sym_op->aead.digest.data = (uint8_t *)rte_pktmbuf_append( + mbuf, vectors[vector_number].digest.len); + + sym_op->aead.data.length = vectors[vector_number].plaintext.len; + sym_op->aead.data.offset = 0; + + if (rte_crypto_op_attach_sym_session(op, sess)) + return -1; + return 0; +} diff --git a/app/test-mp-crypto/mp_crypto.h b/app/test-mp-crypto/mp_crypto.h index fad0230..2616052 100644 --- a/app/test-mp-crypto/mp_crypto.h +++ b/app/test-mp-crypto/mp_crypto.h @@ -7,6 +7,7 @@ #include #include #include +#include "mp_crypto_vectors.h" /* Intel QuickAssist Technology Symmetric service PMD name */ #define CRYPTODEV_NAME_QAT_SYM_PMD "crypto_qat" @@ -32,6 +33,8 @@ #define MP_APP_CRYPTO_OP_POOL_NAME "MP_APP_OP_NAME" /* Mbuf information */ #define MP_APP_MBUFPOOL_NAME "MP_APP_MBUF_NAME" +/* How long to weit before quit when exit flag set */ +#define DEQ_THRESHOLD 100000 extern int mp_crypto_exit_flag; /* Global exit flag */ @@ -189,6 +192,30 @@ int mp_crypto_init_devs(void); int mp_crypto_setup_mpool(void); /* Function to set or lookup for mempools */ +int mp_crypto_init_sessions(void); +/* Function to setup session according to mask */ + +int mp_crypto_setup_ops(void); +/* Function to setup opse according to input string enq=[] */ + +/* Create and init symmetric session */ +struct rte_cryptodev_sym_session *mp_app_create_session + (int dev_id, const struct mp_crypto_session_vector *vector); + +/* Create AEAD session */ +struct rte_cryptodev_sym_session* + mp_app_create_aead_session(int dev_id, + const struct mp_crypto_session_vector *vector); + +/* Create op */ +int +mp_crypto_create_op(struct rte_crypto_op *op, struct rte_mbuf *mbuf, + uint16_t vector_number, + struct rte_cryptodev_sym_session *sess); + +int mp_crypto_flow(void); +/* Flow function for enqueue dequeue */ + #define IV_OFFSET (sizeof(struct rte_crypto_op) + \ sizeof(struct rte_crypto_sym_op) + DEFAULT_NUM_XFORMS * \ sizeof(struct rte_crypto_sym_xform)) diff --git a/app/test-mp-crypto/mp_crypto_vectors.c b/app/test-mp-crypto/mp_crypto_vectors.c new file mode 100644 index 0000000..37a4f68 --- /dev/null +++ b/app/test-mp-crypto/mp_crypto_vectors.c @@ -0,0 +1,174 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020 Intel Corporation + */ +#include "mp_crypto_vectors.h" + +const struct mp_crypto_session_vector session_vectors[] = { + { /* Session 0 */ + .aead_op = RTE_CRYPTO_AEAD_OP_ENCRYPT, + .x_type = RTE_CRYPTO_SYM_XFORM_AEAD, + .aead_algo = RTE_CRYPTO_AEAD_AES_GCM, + .crypto_key = { + .data = { + 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, + 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08 + }, + .len = 16, + }, + .aad_len = 0, + .iv_len = 12, + .digest_len = 16, + }, + { /* Session 1 */ + .aead_op = RTE_CRYPTO_AEAD_OP_ENCRYPT, + .x_type = RTE_CRYPTO_SYM_XFORM_AEAD, + .aead_algo = RTE_CRYPTO_AEAD_AES_GCM, + .crypto_key = { + .data = { + 0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, + 0x6D, 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x08, + 0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C + }, + .len = 24, + }, + .aad_len = 0, + .iv_len = 12, + .digest_len = 16, + }, +}; +const uint64_t mp_app_numof_sessions = + RTE_DIM(session_vectors); +/* Number of all sessions in array */ + +const struct mp_crypto_vector vectors[] = { + { /* Vector 0 AES128-GCM */ + .session = 0, + .plaintext = { + .data = { + 0xd9, 0x31, 0x32, 0x25, + 0xf8, 0x84, 0x06, 0xe5, + 0xa5, 0x59, 0x09, 0xc5, + 0xaf, 0xf5, 0x26, 0x9a, + 0x86, 0xa7, 0xa9, 0x53, + 0x15, 0x34, 0xf7, 0xda, + 0x2e, 0x4c, 0x30, 0x3d, + 0x8a, 0x31, 0x8a, 0x72, + 0x1c, 0x3c, 0x0c, 0x95, + 0x95, 0x68, 0x09, 0x53, + 0x2f, 0xcf, 0x0e, 0x24, + 0x49, 0xa6, 0xb5, 0x25, + 0xb1, 0x6a, 0xed, 0xf5, + 0xaa, 0x0d, 0xe6, 0x57, + 0xba, 0x63, 0x7b, 0x39, + }, + .len = 60, + }, + .iv = { + 0xca, 0xfe, 0xba, 0xbe, + 0xfa, 0xce, 0xdb, 0xad, + 0xde, 0xca, 0xf8, 0x88 + }, + .ciphertext = { + .data = { + 0x42, 0x83, 0x1e, 0xc2, + 0x21, 0x77, 0x74, 0x24, + 0x4b, 0x72, 0x21, 0xb7, + 0x84, 0xd0, 0xd4, 0x9c, + 0xe3, 0xaa, 0x21, 0x2f, + 0x2c, 0x02, 0xa4, 0xe0, + 0x35, 0xc1, 0x7e, 0x23, + 0x29, 0xac, 0xa1, 0x2e, + 0x21, 0xd5, 0x14, 0xb2, + 0x54, 0x66, 0x93, 0x1c, + 0x7d, 0x8f, 0x6a, 0x5a, + 0xac, 0x84, 0xaa, 0x05, + 0x1b, 0xa3, 0x0b, 0x39, + 0x6a, 0x0a, 0xac, 0x97, + 0x3d, 0x58, 0xe0, 0x91 + }, + .len = 60 + }, + .aad = { + .data = { + + }, + }, + .digest = { + .data = { + 0xA2, 0xA4, 0x35, 0x75, + 0xDC, 0xB0, 0x57, 0x74, + 0x07, 0x02, 0x30, 0xC2, + 0xE7, 0x52, 0x02, 0x00}, + .len = 16 + }, + }, + { /* Vector 1 AES192-GCM */ + .session = 1, + .plaintext = { + .data = { + 0xD9, 0x31, 0x32, 0x25, + 0xF8, 0x84, 0x06, 0xE5, + 0xA5, 0x59, 0x09, 0xC5, + 0xAF, 0xF5, 0x26, 0x9A, + 0x86, 0xA7, 0xA9, 0x53, + 0x15, 0x34, 0xF7, 0xDA, + 0x2E, 0x4C, 0x30, 0x3D, + 0x8A, 0x31, 0x8A, 0x72, + 0x1C, 0x3C, 0x0C, 0x95, + 0x95, 0x68, 0x09, 0x53, + 0x2F, 0xCF, 0x0E, 0x24, + 0x49, 0xA6, 0xB5, 0x25, + 0xB1, 0x6A, 0xED, 0xF5, + 0xAA, 0x0D, 0xE6, 0x57, + 0xBA, 0x63, 0x7B, 0x39, + 0x1A, 0xAF, 0xD2, 0x55 + }, + .len = 60, + }, + .iv = { + 0xCA, 0xFE, 0xBA, 0xBE, + 0xFA, 0xCE, 0xDB, 0xAD, + 0xDE, 0xCA, 0xF8, 0x88 + }, + .ciphertext = { + .data = { + 0x39, 0x80, 0xCA, 0x0B, + 0x3C, 0x00, 0xE8, 0x41, + 0xEB, 0x06, 0xFA, 0xC4, + 0x87, 0x2A, 0x27, 0x57, + 0x85, 0x9E, 0x1C, 0xEA, + 0xA6, 0xEF, 0xD9, 0x84, + 0x62, 0x85, 0x93, 0xB4, + 0x0C, 0xA1, 0xE1, 0x9C, + 0x7D, 0x77, 0x3D, 0x00, + 0xC1, 0x44, 0xC5, 0x25, + 0xAC, 0x61, 0x9D, 0x18, + 0xC8, 0x4A, 0x3F, 0x47, + 0x18, 0xE2, 0x44, 0x8B, + 0x2F, 0xE3, 0x24, 0xD9, + 0xCC, 0xDA, 0x27, 0x10, + 0xAC, 0xAD, 0xE2, 0x56 + }, + .len = 60 + }, + .aad = { + .data = { + + }, + }, + .digest = { + .data = { + 0x99, 0x24, 0xA7, 0xC8, + 0x58, 0x73, 0x36, 0xBF, + 0xB1, 0x18, 0x02, 0x4D, + 0xB8, 0x67, 0x4A, 0x14 + }, + .len = 16 + }, + }, + + +}; + +const uint64_t mp_app_numof_ops = RTE_DIM(vectors); +/* Number of all operation instances */ diff --git a/app/test-mp-crypto/mp_crypto_vectors.h b/app/test-mp-crypto/mp_crypto_vectors.h new file mode 100644 index 0000000..65386ad --- /dev/null +++ b/app/test-mp-crypto/mp_crypto_vectors.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2020 Intel Corporation + */ +#ifndef _MP_CRYPTO_SAMPLE_APP_VECTORS_ +#define _MP_CRYPTO_SAMPLE_APP_VECTORS_ + +#include + +struct mp_crypto_session_vector { + union { + enum rte_crypto_aead_algorithm aead_algo; + enum rte_crypto_auth_algorithm auth_algo; + enum rte_crypto_cipher_algorithm cipher_algo; + }; + enum rte_crypto_sym_xform_type x_type; + union { + enum rte_crypto_aead_operation aead_op; + enum rte_crypto_cipher_operation cipher_op; + enum rte_crypto_auth_operation auth_op; + }; + struct { + uint8_t data[64]; + uint16_t len; + } crypto_key; + struct { + uint8_t data[64]; + uint16_t len; + } auth_key; + uint16_t aad_len; + uint16_t iv_len; + uint16_t digest_len; + int chained; +}; + +struct mp_crypto_vector { + int session; + struct { + uint8_t data[2048]; + int len; + } ciphertext; + struct { + uint8_t data[2048]; + int len; + } plaintext; + struct { + uint8_t data[2048]; + int len; + } digest; + struct { + uint8_t data[64]; + } aad; + uint8_t iv[16]; +}; + +/* Predefinced vectors */ +extern const struct mp_crypto_session_vector session_vectors[]; +/* Sessions vectors for this device */ +extern const uint64_t mp_app_numof_sessions; +/* Number of all sessions in array */ + +extern const struct mp_crypto_vector vectors[]; +/* Operation vectors for this device */ +const uint64_t mp_app_numof_ops; +/* Total number of operation types */ + +#endif