From patchwork Thu Sep 5 14:47:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Akhil Goyal X-Patchwork-Id: 58671 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E15671F033; Thu, 5 Sep 2019 17:02:36 +0200 (CEST) Received: from inva021.nxp.com (inva021.nxp.com [92.121.34.21]) by dpdk.org (Postfix) with ESMTP id 82E501F005 for ; Thu, 5 Sep 2019 17:02:26 +0200 (CEST) Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 60E50200106; Thu, 5 Sep 2019 17:02:26 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 61592200248; Thu, 5 Sep 2019 17:02:22 +0200 (CEST) Received: from GDB1.ap.freescale.net (GDB1.ap.freescale.net [10.232.132.179]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 4B53940314; Thu, 5 Sep 2019 23:02:17 +0800 (SGT) From: Akhil Goyal To: dev@dpdk.org Cc: hemant.agrawal@nxp.com, anoobj@marvell.com, jerinj@marvell.com, declan.doherty@intel.com, konstantin.ananyev@intel.com, vakul.garg@nxp.com, Akhil Goyal Date: Thu, 5 Sep 2019 20:17:53 +0530 Message-Id: <20190905144754.10188-7-akhil.goyal@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190905144754.10188-1-akhil.goyal@nxp.com> References: <20190903164911.32091-1-akhil.goyal@nxp.com> <20190905144754.10188-1-akhil.goyal@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Subject: [dpdk-dev] [PATCH 6/7] test/crypto: Add PDCP cases for scatter gather bufs 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" Test cases for PDCP with scattered input and output buffers are added for both inplace and out of place scenarios. 1. input SG - output non SG 2. input and output both SG and inplace buffers 3. input and output both SG with different segment sizes 4. input SG and output non-SG Signed-off-by: Akhil Goyal --- app/test/test_cryptodev.c | 349 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 349 insertions(+) diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index 837969430..568fa84a9 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -7206,6 +7206,276 @@ test_pdcp_proto(int i, int oop, return ret; } +static int +test_pdcp_proto_SGL(int i, int oop, + enum rte_crypto_cipher_operation opc, + enum rte_crypto_auth_operation opa, + uint8_t *input_vec, + unsigned int input_vec_len, + uint8_t *output_vec, + unsigned int output_vec_len, + uint32_t fragsz, + uint32_t fragsz_oop) +{ + struct crypto_testsuite_params *ts_params = &testsuite_params; + struct crypto_unittest_params *ut_params = &unittest_params; + uint8_t *plaintext; + struct rte_mbuf *buf, *buf_oop = NULL; + int ret = TEST_SUCCESS; + int to_trn = 0; + int to_trn_tbl[16]; + int segs = 1; + unsigned int trn_data = 0; + + if (fragsz > input_vec_len) + fragsz = input_vec_len; + + uint16_t plaintext_len = fragsz; + uint16_t frag_size_oop = fragsz_oop ? fragsz_oop : fragsz; + + if (fragsz_oop > output_vec_len) + frag_size_oop = output_vec_len; + + int ecx = 0; + if (input_vec_len % fragsz != 0) { + if (input_vec_len / fragsz + 1 > 16) + return 1; + } else if (input_vec_len / fragsz > 16) + return 1; + + /* Out of place support */ + if (oop) { + /* + * For out-op-place we need to alloc another mbuf + */ + ut_params->obuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); + rte_pktmbuf_append(ut_params->obuf, frag_size_oop); + buf_oop = ut_params->obuf; + } + + /* Generate test mbuf data */ + ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); + + /* clear mbuf payload */ + memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, + rte_pktmbuf_tailroom(ut_params->ibuf)); + + plaintext = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, + plaintext_len); + memcpy(plaintext, input_vec, plaintext_len); + trn_data += plaintext_len; + + buf = ut_params->ibuf; + + /* + * Loop until no more fragments + */ + + while (trn_data < input_vec_len) { + ++segs; + to_trn = (input_vec_len - trn_data < fragsz) ? + (input_vec_len - trn_data) : fragsz; + + to_trn_tbl[ecx++] = to_trn; + + buf->next = rte_pktmbuf_alloc(ts_params->mbuf_pool); + buf = buf->next; + + memset(rte_pktmbuf_mtod(buf, uint8_t *), 0, + rte_pktmbuf_tailroom(buf)); + + /* OOP */ + if (oop && !fragsz_oop) { + buf_oop->next = + rte_pktmbuf_alloc(ts_params->mbuf_pool); + buf_oop = buf_oop->next; + memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), + 0, rte_pktmbuf_tailroom(buf_oop)); + rte_pktmbuf_append(buf_oop, to_trn); + } + + plaintext = (uint8_t *)rte_pktmbuf_append(buf, + to_trn); + + memcpy(plaintext, input_vec + trn_data, to_trn); + trn_data += to_trn; + } + + ut_params->ibuf->nb_segs = segs; + + segs = 1; + if (fragsz_oop && oop) { + to_trn = 0; + ecx = 0; + + trn_data = frag_size_oop; + while (trn_data < output_vec_len) { + ++segs; + to_trn = + (output_vec_len - trn_data < + frag_size_oop) ? + (output_vec_len - trn_data) : + frag_size_oop; + + to_trn_tbl[ecx++] = to_trn; + + buf_oop->next = + rte_pktmbuf_alloc(ts_params->mbuf_pool); + buf_oop = buf_oop->next; + memset(rte_pktmbuf_mtod(buf_oop, uint8_t *), + 0, rte_pktmbuf_tailroom(buf_oop)); + rte_pktmbuf_append(buf_oop, to_trn); + + trn_data += to_trn; + } + ut_params->obuf->nb_segs = segs; + } + + ut_params->type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL; + + /* Setup Cipher Parameters */ + ut_params->cipher_xform.type = RTE_CRYPTO_SYM_XFORM_CIPHER; + ut_params->cipher_xform.cipher.algo = pdcp_test_params[i].cipher_alg; + ut_params->cipher_xform.cipher.op = opc; + ut_params->cipher_xform.cipher.key.data = pdcp_test_crypto_key[i]; + ut_params->cipher_xform.cipher.key.length = + pdcp_test_params[i].cipher_key_len; + ut_params->cipher_xform.cipher.iv.length = 0; + + /* Setup HMAC Parameters if ICV header is required */ + if (pdcp_test_params[i].auth_alg != 0) { + ut_params->auth_xform.type = RTE_CRYPTO_SYM_XFORM_AUTH; + ut_params->auth_xform.next = NULL; + ut_params->auth_xform.auth.algo = pdcp_test_params[i].auth_alg; + ut_params->auth_xform.auth.op = opa; + ut_params->auth_xform.auth.key.data = pdcp_test_auth_key[i]; + ut_params->auth_xform.auth.key.length = + pdcp_test_params[i].auth_key_len; + + ut_params->cipher_xform.next = &ut_params->auth_xform; + } else { + ut_params->cipher_xform.next = NULL; + } + + struct rte_security_session_conf sess_conf = { + .action_type = RTE_SECURITY_ACTION_TYPE_LOOKASIDE_PROTOCOL, + .protocol = RTE_SECURITY_PROTOCOL_PDCP, + {.pdcp = { + .bearer = pdcp_test_bearer[i], + .domain = pdcp_test_params[i].domain, + .pkt_dir = pdcp_test_packet_direction[i], + .sn_size = pdcp_test_data_sn_size[i], + .hfn = pdcp_test_hfn[i], + .hfn_threshold = pdcp_test_hfn_threshold[i], + } }, + .crypto_xform = &ut_params->cipher_xform + }; + + struct rte_security_ctx *ctx = (struct rte_security_ctx *) + rte_cryptodev_get_sec_ctx( + ts_params->valid_devs[0]); + + /* Create security session */ + ut_params->sec_session = rte_security_session_create(ctx, + &sess_conf, ts_params->session_mpool); + + if (!ut_params->sec_session) { + printf("TestCase %s()-%d line %d failed %s: ", + __func__, i, __LINE__, "Failed to allocate session"); + ret = TEST_FAILED; + goto on_err; + } + + /* Generate crypto op data structure */ + ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, + RTE_CRYPTO_OP_TYPE_SYMMETRIC); + if (!ut_params->op) { + printf("TestCase %s()-%d line %d failed %s: ", + __func__, i, __LINE__, + "Failed to allocate symmetric crypto operation struct"); + ret = TEST_FAILED; + goto on_err; + } + + rte_security_attach_session(ut_params->op, ut_params->sec_session); + + /* set crypto operation source mbuf */ + ut_params->op->sym->m_src = ut_params->ibuf; + if (oop) + ut_params->op->sym->m_dst = ut_params->obuf; + + /* Process crypto operation */ + if (process_crypto_request(ts_params->valid_devs[0], ut_params->op) + == NULL) { + printf("TestCase %s()-%d line %d failed %s: ", + __func__, i, __LINE__, + "failed to process sym crypto op"); + ret = TEST_FAILED; + goto on_err; + } + + if (ut_params->op->status != RTE_CRYPTO_OP_STATUS_SUCCESS) { + printf("TestCase %s()-%d line %d failed %s: ", + __func__, i, __LINE__, "crypto op processing failed"); + ret = TEST_FAILED; + goto on_err; + } + + /* Validate obuf */ + uint8_t *ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_src, + uint8_t *); + if (oop) { + ciphertext = rte_pktmbuf_mtod(ut_params->op->sym->m_dst, + uint8_t *); + } + if (fragsz_oop) + fragsz = frag_size_oop; + if (memcmp(ciphertext, output_vec, fragsz)) { + printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); + rte_hexdump(stdout, "encrypted", ciphertext, fragsz); + rte_hexdump(stdout, "reference", output_vec, fragsz); + ret = TEST_FAILED; + goto on_err; + } + + buf = ut_params->op->sym->m_src->next; + if (oop) + buf = ut_params->op->sym->m_dst->next; + + unsigned int off = fragsz; + + ecx = 0; + while (buf) { + ciphertext = rte_pktmbuf_mtod(buf, + uint8_t *); + if (memcmp(ciphertext, output_vec + off, to_trn_tbl[ecx])) { + printf("\n=======PDCP TestCase #%d failed: Data Mismatch ", i); + rte_hexdump(stdout, "encrypted", ciphertext, to_trn_tbl[ecx]); + rte_hexdump(stdout, "reference", output_vec + off, to_trn_tbl[ecx]); + ret = TEST_FAILED; + goto on_err; + } + off += to_trn_tbl[ecx++]; + buf = buf->next; + } +on_err: + rte_crypto_op_free(ut_params->op); + ut_params->op = NULL; + + if (ut_params->sec_session) + rte_security_session_destroy(ctx, ut_params->sec_session); + ut_params->sec_session = NULL; + + rte_pktmbuf_free(ut_params->ibuf); + ut_params->ibuf = NULL; + if (oop) { + rte_pktmbuf_free(ut_params->obuf); + ut_params->obuf = NULL; + } + + return ret; +} + int test_pdcp_proto_cplane_encap(int i) { @@ -7279,6 +7549,67 @@ test_pdcp_proto_uplane_decap_with_int(int i) pdcp_test_data_in_len[i]); } +static int +test_PDCP_PROTO_SGL_in_place_32B(void) +{ + /* i can be used for running any PDCP case + * In this case it is uplane 12-bit AES-SNOW DL encap */ + int i = PDCP_UPLANE_12BIT_OFFSET + AES_ENC + SNOW_AUTH + DOWNLINK; + return test_pdcp_proto_SGL(i, IN_PLACE, + RTE_CRYPTO_CIPHER_OP_ENCRYPT, + RTE_CRYPTO_AUTH_OP_GENERATE, + pdcp_test_data_in[i], + pdcp_test_data_in_len[i], + pdcp_test_data_out[i], + pdcp_test_data_in_len[i]+4, + 32, 0); +} +static int +test_PDCP_PROTO_SGL_oop_32B_128B(void) +{ + /* i can be used for running any PDCP case + * In this case it is uplane 18-bit NULL-NULL DL encap */ + int i = PDCP_UPLANE_18BIT_OFFSET + NULL_ENC + NULL_AUTH + DOWNLINK; + return test_pdcp_proto_SGL(i, OUT_OF_PLACE, + RTE_CRYPTO_CIPHER_OP_ENCRYPT, + RTE_CRYPTO_AUTH_OP_GENERATE, + pdcp_test_data_in[i], + pdcp_test_data_in_len[i], + pdcp_test_data_out[i], + pdcp_test_data_in_len[i]+4, + 32, 128); +} +static int +test_PDCP_PROTO_SGL_oop_32B_40B(void) +{ + /* i can be used for running any PDCP case + * In this case it is uplane 18-bit AES DL encap */ + int i = PDCP_UPLANE_OFFSET + AES_ENC + EIGHTEEN_BIT_SEQ_NUM_OFFSET + + DOWNLINK; + return test_pdcp_proto_SGL(i, OUT_OF_PLACE, + RTE_CRYPTO_CIPHER_OP_ENCRYPT, + RTE_CRYPTO_AUTH_OP_GENERATE, + pdcp_test_data_in[i], + pdcp_test_data_in_len[i], + pdcp_test_data_out[i], + pdcp_test_data_in_len[i], + 32, 40); +} +static int +test_PDCP_PROTO_SGL_oop_128B_32B(void) +{ + /* i can be used for running any PDCP case + * In this case it is cplane 12-bit AES-ZUC DL encap */ + int i = PDCP_CPLANE_LONG_SN_OFFSET + AES_ENC + ZUC_AUTH + DOWNLINK; + return test_pdcp_proto_SGL(i, OUT_OF_PLACE, + RTE_CRYPTO_CIPHER_OP_ENCRYPT, + RTE_CRYPTO_AUTH_OP_GENERATE, + pdcp_test_data_in[i], + pdcp_test_data_in_len[i], + pdcp_test_data_out[i], + pdcp_test_data_in_len[i]+4, + 128, 32); +} #endif static int @@ -11705,6 +12036,15 @@ static struct unit_test_suite cryptodev_dpaa_sec_testsuite = { TEST_CASE_ST(ut_setup, ut_teardown, test_PDCP_PROTO_uplane_decap_all), + + TEST_CASE_ST(ut_setup, ut_teardown, + test_PDCP_PROTO_SGL_in_place_32B), + TEST_CASE_ST(ut_setup, ut_teardown, + test_PDCP_PROTO_SGL_oop_32B_128B), + TEST_CASE_ST(ut_setup, ut_teardown, + test_PDCP_PROTO_SGL_oop_32B_40B), + TEST_CASE_ST(ut_setup, ut_teardown, + test_PDCP_PROTO_SGL_oop_128B_32B), #endif /** AES GCM Authenticated Encryption */ TEST_CASE_ST(ut_setup, ut_teardown, @@ -11823,6 +12163,15 @@ static struct unit_test_suite cryptodev_dpaa2_sec_testsuite = { TEST_CASE_ST(ut_setup, ut_teardown, test_PDCP_PROTO_uplane_decap_all), + + TEST_CASE_ST(ut_setup, ut_teardown, + test_PDCP_PROTO_SGL_in_place_32B), + TEST_CASE_ST(ut_setup, ut_teardown, + test_PDCP_PROTO_SGL_oop_32B_128B), + TEST_CASE_ST(ut_setup, ut_teardown, + test_PDCP_PROTO_SGL_oop_32B_40B), + TEST_CASE_ST(ut_setup, ut_teardown, + test_PDCP_PROTO_SGL_oop_128B_32B), #endif /** AES GCM Authenticated Encryption */ TEST_CASE_ST(ut_setup, ut_teardown,