From patchwork Fri Aug 11 09:42:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tejasree Kondoj X-Patchwork-Id: 130150 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 1AF2E43032; Fri, 11 Aug 2023 11:42:44 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0CB0043247; Fri, 11 Aug 2023 11:42:44 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 237CB40E03 for ; Fri, 11 Aug 2023 11:42:42 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37AMjlQE001536; Fri, 11 Aug 2023 02:42:42 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=pfpt0220; bh=qivURTX6cpxsILXZTKTHM2rQm9wJSeJ6lrJyt21kxgY=; b=TkRdTq4aDpsH+eLYx1qg1NBuX9jW6i83OE6DS6JreyoNP4yiVpvoH5UAKsGA6t1G5oCF 80FxMjVi4Ibr1/yfQlRck4yOrl10o8dxQXkrnEBroKMgFTeB+kAJNbx+72FfIL724PVs GMc9B0vrpMtVskpfq84byBe62xt4yc6j1q8+22PpyK280mXFVh3DQbbtjGV6GVnKv3wk Jr7zRgcR4lZMk3xiH9MfZajfh4QaIRtEfMWMh/jVNY1vJzPRT2KAjwQtNY0gmvg/iGl3 1odm3Bpa+4wzdJ4bIfa8jRGW/metaxVwB951OkX9vVMa0QHZysLhSp9DxoZsS/+2f91z Ug== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3sd8yp9w50-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 11 Aug 2023 02:42:42 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Fri, 11 Aug 2023 02:42:40 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Fri, 11 Aug 2023 02:42:40 -0700 Received: from hyd1554.marvell.com (unknown [10.29.57.11]) by maili.marvell.com (Postfix) with ESMTP id 8F5E83F7055; Fri, 11 Aug 2023 02:42:38 -0700 (PDT) From: Tejasree Kondoj To: Akhil Goyal , Fan Zhang , Ciara Power CC: Anoob Joseph , Subject: [PATCH] app/test: add external mbuf IPsec tests Date: Fri, 11 Aug 2023 15:12:37 +0530 Message-ID: <20230811094237.38181-1-ktejasree@marvell.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: hVMUGkpQVFAylXWcCBh66eewaOh8Ph6s X-Proofpoint-GUID: hVMUGkpQVFAylXWcCBh66eewaOh8Ph6s X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-08-10_20,2023-08-10_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 --- 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 cbf2bb7c62..fda32559ab 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -9811,6 +9811,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 uint8_t *input_text) +{ + struct rte_mbuf *m = NULL, *mbuf = NULL; + uint64_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(RTE_PTR_ADD(ext_buf_addr, 0), 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[], @@ -10026,9 +10153,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, @@ -10099,6 +10231,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; @@ -10129,6 +10264,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) { @@ -10746,6 +10902,27 @@ test_ipsec_proto_sgl(const void *data __rte_unused) return test_ipsec_proto_all(&flags); } +static int +test_ipsec_proto_sgl_ext_mbuf(const void *data __rte_unused) +{ + 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, @@ -15825,6 +16002,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, @@ -16207,6 +16388,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 5606ec056d..e7903e9334 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;