From patchwork Wed Sep 20 07:22:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tejasree Kondoj X-Patchwork-Id: 131674 X-Patchwork-Delegate: gakhil@marvell.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 56F2A425E4; Wed, 20 Sep 2023 09:22:38 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 41E7740DCB; Wed, 20 Sep 2023 09:22:38 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 43CCB406B8 for ; Wed, 20 Sep 2023 09:22:36 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38K67q4w012755; Wed, 20 Sep 2023 00:22:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=pfpt0220; bh=m+wDKSdWiNudBwUkzzctG1L9BRhXMiown/1qKXlnzI4=; b=VrSrOV6wjQ8oxjk7WBNM/r3xRvf4blhXITiB+5liMG0bjkhS0mwYBNh8fQdtymXMzIvn roF10ER+0gZhOcfFPO72gX4KjtJ6sptxTT5N8WEknPjBf64YdKYdRY9R2XaJ7LKLDNY5 V3RM0oRMAlBosRblFplqUvBWDcM18McYBcha6QsGeLcNE8urNdLHNC5VHgIsGEkxFJan Oy0vfzeduRrcKfAWdObMznsZw7N9aS01E3Gas/UZX+kRL8CbuVk4rTAOczmVSzwsQ4RC rIDGCuDrxlDeDZlmQH8f/Goj4T9ZRjj4nTxG/JWe2NRajwW6RNMA6DZzyKYdsGyrxSX2 7w== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3t7htasy9n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 20 Sep 2023 00:22:35 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 20 Sep 2023 00:22:33 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Wed, 20 Sep 2023 00:22:33 -0700 Received: from hyd1554.marvell.com (unknown [10.29.57.11]) by maili.marvell.com (Postfix) with ESMTP id B86AB5B6926; Wed, 20 Sep 2023 00:22:31 -0700 (PDT) From: Tejasree Kondoj To: Akhil Goyal , Fan Zhang , Ciara Power CC: Anoob Joseph , Subject: [PATCH v3] app/test: add external mbuf IPsec tests Date: Wed, 20 Sep 2023 12:52:30 +0530 Message-ID: <20230920072230.2026381-1-ktejasree@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230814064737.197477-1-ktejasree@marvell.com> References: <20230814064737.197477-1-ktejasree@marvell.com> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: lgP4vR-uA7bqiAN_rHEBRpMKwF1bK0Ix X-Proofpoint-GUID: lgP4vR-uA7bqiAN_rHEBRpMKwF1bK0Ix X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-20_02,2023-09-19_01,2023-05-22_02 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Adding IPsec tests using external mbuf API. Signed-off-by: Tejasree Kondoj --- v3: - Rebased and fixed Intel compilation failure. v2: - Fixed compilation with ubuntu-20.04-gcc-static-i386. app/test/test_cryptodev.c | 191 ++++++++++++++++++++++- app/test/test_cryptodev_security_ipsec.h | 1 + 2 files changed, 189 insertions(+), 3 deletions(-) diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index 049ee17d41..22e9800779 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -9754,6 +9754,133 @@ test_PDCP_SDAP_PROTO_decap_all(void) return (all_err == TEST_SUCCESS) ? TEST_SUCCESS : TEST_FAILED; } +static inline void +ext_mbuf_callback_fn_free(void *addr __rte_unused, void *opaque __rte_unused) +{ +} + +static inline void +ext_mbuf_memzone_free(int nb_segs) +{ + int i; + + for (i = 0; i <= nb_segs; i++) { + char mz_name[RTE_MEMZONE_NAMESIZE]; + const struct rte_memzone *memzone; + snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i); + memzone = rte_memzone_lookup(mz_name); + if (memzone != NULL) { + rte_memzone_free(memzone); + memzone = NULL; + } + } +} + +static inline struct rte_mbuf * +ext_mbuf_create(struct rte_mempool *mbuf_pool, int pkt_len, + int nb_segs, const void *input_text) +{ + struct rte_mbuf *m = NULL, *mbuf = NULL; + size_t data_off = 0; + uint8_t *dst; + int i, size; + int t_len; + + if (pkt_len < 1) { + printf("Packet size must be 1 or more (is %d)\n", pkt_len); + return NULL; + } + + if (nb_segs < 1) { + printf("Number of segments must be 1 or more (is %d)\n", + nb_segs); + return NULL; + } + + t_len = pkt_len >= nb_segs ? pkt_len / nb_segs : 1; + size = pkt_len; + + /* Create chained mbuf_src with external buffer */ + for (i = 0; size > 0; i++) { + struct rte_mbuf_ext_shared_info *ret_shinfo = NULL; + uint16_t data_len = RTE_MIN(size, t_len); + char mz_name[RTE_MEMZONE_NAMESIZE]; + const struct rte_memzone *memzone; + void *ext_buf_addr = NULL; + rte_iova_t buf_iova; + bool freed = false; + uint16_t buf_len; + + buf_len = RTE_ALIGN_CEIL(data_len + 1024 + + sizeof(struct rte_mbuf_ext_shared_info), 8); + + snprintf(mz_name, RTE_MEMZONE_NAMESIZE, "ext_buf_%d", i); + memzone = rte_memzone_lookup(mz_name); + if (memzone != NULL && memzone->len != buf_len) { + rte_memzone_free(memzone); + memzone = NULL; + } + if (memzone == NULL) { + memzone = rte_memzone_reserve_aligned(mz_name, buf_len, SOCKET_ID_ANY, + RTE_MEMZONE_IOVA_CONTIG, RTE_CACHE_LINE_SIZE); + if (memzone == NULL) { + printf("Can't allocate memory zone %s\n", mz_name); + return NULL; + } + } + + ext_buf_addr = memzone->addr; + memcpy(ext_buf_addr, RTE_PTR_ADD(input_text, data_off), data_len); + + /* Create buffer to hold rte_mbuf header */ + m = rte_pktmbuf_alloc(mbuf_pool); + if (i == 0) + mbuf = m; + + if (m == NULL) { + printf("Cannot create segment for source mbuf"); + goto fail; + } + + /* Save shared data (like callback function) in external buffer’s end */ + ret_shinfo = rte_pktmbuf_ext_shinfo_init_helper(ext_buf_addr, &buf_len, + ext_mbuf_callback_fn_free, &freed); + if (ret_shinfo == NULL) { + printf("Shared mem initialization failed!\n"); + goto fail; + } + + buf_iova = rte_mem_virt2iova(ext_buf_addr); + + /* Attach external buffer to mbuf */ + rte_pktmbuf_attach_extbuf(m, ext_buf_addr, buf_iova, buf_len, + ret_shinfo); + if (m->ol_flags != RTE_MBUF_F_EXTERNAL) { + printf("External buffer is not attached to mbuf\n"); + goto fail; + } + + dst = (uint8_t *)rte_pktmbuf_append(m, data_len); + if (dst == NULL) { + printf("Cannot append %d bytes to the mbuf\n", data_len); + goto fail; + } + + if (mbuf != m) + rte_pktmbuf_chain(mbuf, m); + + size -= data_len; + data_off += data_len; + } + + return mbuf; + +fail: + rte_pktmbuf_free(mbuf); + ext_mbuf_memzone_free(nb_segs); + return NULL; +} + static int test_ipsec_proto_process(const struct ipsec_test_data td[], struct ipsec_test_data res_d[], @@ -9969,9 +10096,14 @@ test_ipsec_proto_process(const struct ipsec_test_data td[], return TEST_FAILED; /* Setup source mbuf payload */ - ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, td[i].input_text.len, - nb_segs, 0); - pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, input_text); + if (flags->use_ext_mbuf) { + ut_params->ibuf = ext_mbuf_create(ts_params->mbuf_pool, + td[i].input_text.len, nb_segs, input_text); + } else { + ut_params->ibuf = create_segmented_mbuf(ts_params->mbuf_pool, + td[i].input_text.len, nb_segs, 0); + pktmbuf_write(ut_params->ibuf, 0, td[i].input_text.len, input_text); + } /* Generate crypto op data structure */ ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, @@ -10042,6 +10174,9 @@ test_ipsec_proto_process(const struct ipsec_test_data td[], rte_crypto_op_free(ut_params->op); ut_params->op = NULL; + if (flags->use_ext_mbuf) + ext_mbuf_memzone_free(nb_segs); + rte_pktmbuf_free(ut_params->ibuf); ut_params->ibuf = NULL; @@ -10072,6 +10207,27 @@ test_ipsec_proto_known_vec(const void *test_data) return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); } +static int +test_ipsec_proto_known_vec_ext_mbuf(const void *test_data) +{ + struct ipsec_test_data td_outb; + struct ipsec_test_flags flags; + + memset(&flags, 0, sizeof(flags)); + flags.use_ext_mbuf = true; + + memcpy(&td_outb, test_data, sizeof(td_outb)); + + if (td_outb.aes_gmac || td_outb.aead || + ((td_outb.ipsec_xform.proto != RTE_SECURITY_IPSEC_SA_PROTO_AH) && + (td_outb.xform.chain.cipher.cipher.algo != RTE_CRYPTO_CIPHER_NULL))) { + /* Disable IV gen to be able to test with known vectors */ + td_outb.ipsec_xform.options.iv_gen_disable = 1; + } + + return test_ipsec_proto_process(&td_outb, NULL, 1, false, &flags); +} + static int test_ipsec_proto_known_vec_inb(const void *test_data) { @@ -10689,6 +10845,27 @@ test_ipsec_proto_sgl(void) return test_ipsec_proto_all(&flags); } +static int +test_ipsec_proto_sgl_ext_mbuf(void) +{ + struct crypto_testsuite_params *ts_params = &testsuite_params; + struct rte_cryptodev_info dev_info; + + struct ipsec_test_flags flags = { + .nb_segs_in_mbuf = 5, + .use_ext_mbuf = 1 + }; + + rte_cryptodev_info_get(ts_params->valid_devs[0], &dev_info); + if (!(dev_info.feature_flags & RTE_CRYPTODEV_FF_IN_PLACE_SGL)) { + printf("Device doesn't support in-place scatter-gather. " + "Test Skipped.\n"); + return TEST_SKIPPED; + } + + return test_ipsec_proto_all(&flags); +} + static int test_ipsec_pkt_replay(const void *test_data, const uint64_t esn[], bool replayed_pkt[], uint32_t nb_pkts, bool esn_en, @@ -15762,6 +15939,10 @@ static struct unit_test_suite ipsec_proto_testsuite = { "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 128)", ut_setup_security, ut_teardown, test_ipsec_proto_known_vec, &pkt_aes_128_gcm), + TEST_CASE_NAMED_WITH_DATA( + "Outbound known vector ext_mbuf mode (ESP tunnel mode IPv4 AES-GCM 128)", + ut_setup_security, ut_teardown, + test_ipsec_proto_known_vec_ext_mbuf, &pkt_aes_128_gcm), TEST_CASE_NAMED_WITH_DATA( "Outbound known vector (ESP tunnel mode IPv4 AES-GCM 192)", ut_setup_security, ut_teardown, @@ -16144,6 +16325,10 @@ static struct unit_test_suite ipsec_proto_testsuite = { "Multi-segmented mode", ut_setup_security, ut_teardown, test_ipsec_proto_sgl), + TEST_CASE_NAMED_ST( + "Multi-segmented external mbuf mode", + ut_setup_security, ut_teardown, + test_ipsec_proto_sgl_ext_mbuf), TEST_CASES_END() /**< NULL terminate unit test array */ } }; diff --git a/app/test/test_cryptodev_security_ipsec.h b/app/test/test_cryptodev_security_ipsec.h index 92e641ba0b..273bbef222 100644 --- a/app/test/test_cryptodev_security_ipsec.h +++ b/app/test/test_cryptodev_security_ipsec.h @@ -103,6 +103,7 @@ struct ipsec_test_flags { bool fragment; bool stats_success; bool antireplay; + bool use_ext_mbuf; enum df_flags df; enum dscp_flags dscp; enum flabel_flags flabel;