From patchwork Wed Nov 30 10:14:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Volodymyr Fialko X-Patchwork-Id: 120351 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 427D3A00C2; Wed, 30 Nov 2022 11:14:26 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D73E840151; Wed, 30 Nov 2022 11:14:25 +0100 (CET) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id C3FF84014F for ; Wed, 30 Nov 2022 11:14:24 +0100 (CET) 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 2AU1PEsL023203; Wed, 30 Nov 2022 02:14:24 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=EAhKHaPcb8+0fXtJkwco99M76oK5Cb2WTqWkCDI0Kkg=; b=OpTl7pilQDeu16UsUgHzF6iaqSfsRz7VaiABjueuTHd7CaWhoQqbirK/DmrldG0f62XT Rpg7KOzjzpcrrMOmpHJq/wg4ABJsxEQfrs2kM56PQwVtINBOlTnPk3BxlUtOMGTff4XK VDqmr1yTFlK4J4ZI1rHRseNLpo+CNs14DMCQ7O7mKvi8OVfyHVpaz/Trpg385Rqj3ZkF XKpepA59Wvz+lnaRpQ4Svs2GiudmjrkuGR66UmSjytiUf+9qTPipuNP8MUutMLAFidwh gmMdYzEle8Jk65ju9JPcL6bneE/S5XrnJ3VVW+gM4owey6taUMnO1gneRbSMUzKYFteA JQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3m3k6wf7re-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 30 Nov 2022 02:14:23 -0800 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 30 Nov 2022 02:14:21 -0800 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.2 via Frontend Transport; Wed, 30 Nov 2022 02:14:21 -0800 Received: from localhost.localdomain (unknown [10.28.34.39]) by maili.marvell.com (Postfix) with ESMTP id 2A6603F7048; Wed, 30 Nov 2022 02:14:18 -0800 (PST) From: Volodymyr Fialko To: , Akhil Goyal , Fan Zhang CC: , , Volodymyr Fialko , Archana Muniganti Subject: [PATCH] test/crypto: add scatter-gather test cases Date: Wed, 30 Nov 2022 11:14:16 +0100 Message-ID: <20221130101416.1392243-1-vfialko@marvell.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Proofpoint-GUID: j24N7Lv7wwwxdnurG_DED1oQ3NqKWgTf X-Proofpoint-ORIG-GUID: j24N7Lv7wwwxdnurG_DED1oQ3NqKWgTf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-11-30_04,2022-11-30_01,2022-06-22_01 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 Add test cases to verify scatter-gather (SGL) buffers, with multiple segments. Signed-off-by: Volodymyr Fialko Signed-off-by: Archana Muniganti Acked-by: Akhil Goyal --- app/test/test_cryptodev.c | 49 ++++++++++--- app/test/test_cryptodev_security_ipsec.c | 93 +++++++++--------------- app/test/test_cryptodev_security_ipsec.h | 3 +- 3 files changed, 74 insertions(+), 71 deletions(-) diff --git a/app/test/test_cryptodev.c b/app/test/test_cryptodev.c index d6ae762df9..dd71947ae8 100644 --- a/app/test/test_cryptodev.c +++ b/app/test/test_cryptodev.c @@ -9348,6 +9348,7 @@ test_ipsec_proto_process(const struct ipsec_test_data td[], 0xe82c, 0x4887}; const struct rte_ipv4_hdr *ipv4 = (const struct rte_ipv4_hdr *)td[0].output_text.data; + int nb_segs = flags->nb_segs_in_mbuf ? flags->nb_segs_in_mbuf : 1; struct crypto_testsuite_params *ts_params = &testsuite_params; struct crypto_unittest_params *ut_params = &unittest_params; struct rte_security_capability_idx sec_cap_idx; @@ -9356,9 +9357,9 @@ test_ipsec_proto_process(const struct ipsec_test_data td[], uint8_t dev_id = ts_params->valid_devs[0]; enum rte_security_ipsec_sa_direction dir; struct ipsec_test_data *res_d_tmp = NULL; + uint8_t input_text[IPSEC_TEXT_MAX_LEN]; int salt_len, i, ret = TEST_SUCCESS; struct rte_security_ctx *ctx; - uint8_t *input_text; uint32_t src, dst; uint32_t verify; @@ -9543,20 +9544,16 @@ test_ipsec_proto_process(const struct ipsec_test_data td[], } } - /* Setup source mbuf payload */ - ut_params->ibuf = rte_pktmbuf_alloc(ts_params->mbuf_pool); - memset(rte_pktmbuf_mtod(ut_params->ibuf, uint8_t *), 0, - rte_pktmbuf_tailroom(ut_params->ibuf)); - - input_text = (uint8_t *)rte_pktmbuf_append(ut_params->ibuf, - td[i].input_text.len); - - memcpy(input_text, td[i].input_text.data, - td[i].input_text.len); - + /* Copy test data before modification */ + memcpy(input_text, td[i].input_text.data, td[i].input_text.len); if (test_ipsec_pkt_update(input_text, flags)) 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); + /* Generate crypto op data structure */ ut_params->op = rte_crypto_op_alloc(ts_params->op_mpool, RTE_CRYPTO_OP_TYPE_SYMMETRIC); @@ -10253,6 +10250,30 @@ test_ipsec_proto_ipv6_set_dscp_1_inner_0(const void *data __rte_unused) return test_ipsec_proto_all(&flags); } +static int +test_ipsec_proto_sgl(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 + }; + + if (gbl_driver_id == rte_cryptodev_driver_id_get( + RTE_STR(CRYPTODEV_NAME_CN10K_PMD))) + return TEST_SKIPPED; + + 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, @@ -15564,6 +15585,10 @@ static struct unit_test_suite ipsec_proto_testsuite = { "Tunnel header IPv6 decrement inner hop limit", ut_setup_security, ut_teardown, test_ipsec_proto_ipv6_hop_limit_decrement), + TEST_CASE_NAMED_ST( + "Multi-segmented mode", + ut_setup_security, ut_teardown, + test_ipsec_proto_sgl), TEST_CASES_END() /**< NULL terminate unit test array */ } }; diff --git a/app/test/test_cryptodev_security_ipsec.c b/app/test/test_cryptodev_security_ipsec.c index 833be94c09..89c63ee028 100644 --- a/app/test/test_cryptodev_security_ipsec.c +++ b/app/test/test_cryptodev_security_ipsec.c @@ -664,12 +664,12 @@ test_ipsec_tunnel_hdr_len_get(const struct ipsec_test_data *td) } static int -test_ipsec_iv_verify_push(struct rte_mbuf *m, const struct ipsec_test_data *td) +test_ipsec_iv_verify_push(const uint8_t *output_text, const struct ipsec_test_data *td) { static uint8_t iv_queue[IV_LEN_MAX * IPSEC_TEST_PACKETS_MAX]; - uint8_t *iv_tmp, *output_text = rte_pktmbuf_mtod(m, uint8_t *); int i, iv_pos, iv_len; static int index; + uint8_t *iv_tmp; if (td->aead) iv_len = td->xform.aead.aead.iv.length - td->salt.len; @@ -704,12 +704,12 @@ test_ipsec_iv_verify_push(struct rte_mbuf *m, const struct ipsec_test_data *td) } static int -test_ipsec_l3_csum_verify(struct rte_mbuf *m) +test_ipsec_l3_csum_verify(uint8_t *output_text) { uint16_t actual_cksum, expected_cksum; struct rte_ipv4_hdr *ip; - ip = rte_pktmbuf_mtod(m, struct rte_ipv4_hdr *); + ip = (struct rte_ipv4_hdr *)output_text; if (!is_ipv4((void *)ip)) return TEST_SKIPPED; @@ -727,26 +727,16 @@ test_ipsec_l3_csum_verify(struct rte_mbuf *m) } static int -test_ipsec_l4_csum_verify(struct rte_mbuf *m) +test_ipsec_l4_csum_verify(uint8_t *output_text) { uint16_t actual_cksum = 0, expected_cksum = 0; - uint32_t len = rte_pktmbuf_pkt_len(m); - uint8_t data_arr[IPSEC_TEXT_MAX_LEN]; struct rte_ipv4_hdr *ipv4; struct rte_ipv6_hdr *ipv6; - uint8_t *data = data_arr; struct rte_tcp_hdr *tcp; struct rte_udp_hdr *udp; - const uint8_t *ptr; void *ip, *l4; - ptr = rte_pktmbuf_read(m, 0, len, data_arr); - if (!ptr) - return -EINVAL; - else if (ptr != data_arr) - data = rte_pktmbuf_mtod_offset(m, uint8_t *, 0); - - ip = (struct rte_ipv4_hdr *)data; + ip = output_text; if (is_ipv4(ip)) { ipv4 = ip; @@ -823,14 +813,11 @@ test_ipsec_ttl_or_hop_decrement_verify(void *received, void *expected) } static int -test_ipsec_td_verify(struct rte_mbuf *m, const struct ipsec_test_data *td, - bool silent, const struct ipsec_test_flags *flags) +test_ipsec_td_verify(uint8_t *output_text, uint32_t len, uint32_t ol_flags, + const struct ipsec_test_data *td, bool silent, const struct ipsec_test_flags *flags) { - uint32_t skip, len = rte_pktmbuf_pkt_len(m); uint8_t td_output_text[IPSEC_TEXT_MAX_LEN]; - uint8_t data_arr[IPSEC_TEXT_MAX_LEN]; - uint8_t *output_text = data_arr; - const uint8_t *ptr; + uint32_t skip; int ret; /* For tests with status as error for test success, skip verification */ @@ -841,12 +828,6 @@ test_ipsec_td_verify(struct rte_mbuf *m, const struct ipsec_test_data *td, td->ar_packet)) return TEST_SUCCESS; - ptr = rte_pktmbuf_read(m, 0, len, data_arr); - if (!ptr) - return -EINVAL; - else if (ptr != data_arr) - output_text = rte_pktmbuf_mtod_offset(m, uint8_t *, 0); - if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS && flags->udp_encap) { @@ -870,15 +851,10 @@ test_ipsec_td_verify(struct rte_mbuf *m, const struct ipsec_test_data *td, } } - skip = test_ipsec_tunnel_hdr_len_get(td); - - len -= skip; - output_text += skip; - if ((td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && flags->ip_csum) { - if (m->ol_flags & RTE_MBUF_F_RX_IP_CKSUM_GOOD) - ret = test_ipsec_l3_csum_verify(m); + if (ol_flags & RTE_MBUF_F_RX_IP_CKSUM_GOOD) + ret = test_ipsec_l3_csum_verify(output_text); else ret = TEST_FAILED; @@ -890,8 +866,8 @@ test_ipsec_td_verify(struct rte_mbuf *m, const struct ipsec_test_data *td, if ((td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && flags->l4_csum) { - if (m->ol_flags & RTE_MBUF_F_RX_L4_CKSUM_GOOD) - ret = test_ipsec_l4_csum_verify(m); + if (ol_flags & RTE_MBUF_F_RX_L4_CKSUM_GOOD) + ret = test_ipsec_l4_csum_verify(output_text); else ret = TEST_FAILED; @@ -901,6 +877,11 @@ test_ipsec_td_verify(struct rte_mbuf *m, const struct ipsec_test_data *td, return ret; } + skip = test_ipsec_tunnel_hdr_len_get(td); + + len -= skip; + output_text += skip; + memcpy(td_output_text, td->output_text.data + skip, len); if ((td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS) && @@ -932,25 +913,13 @@ test_ipsec_td_verify(struct rte_mbuf *m, const struct ipsec_test_data *td, } static int -test_ipsec_res_d_prepare(struct rte_mbuf *m, const struct ipsec_test_data *td, - struct ipsec_test_data *res_d) +test_ipsec_res_d_prepare(const uint8_t *output_text, uint32_t len, + const struct ipsec_test_data *td, struct ipsec_test_data *res_d) { - uint8_t *output_text = rte_pktmbuf_mtod(m, uint8_t *); - uint32_t len = rte_pktmbuf_pkt_len(m); - struct rte_mbuf *next = m; - uint32_t off = 0; - memcpy(res_d, td, sizeof(*res_d)); - while (next && off < len) { - output_text = rte_pktmbuf_mtod(next, uint8_t *); - if (off + next->data_len > sizeof(res_d->input_text.data)) - break; - memcpy(&res_d->input_text.data[off], output_text, next->data_len); - off += next->data_len; - next = next->next; - } - res_d->input_text.len = off; + memcpy(&res_d->input_text.data, output_text, len); + res_d->input_text.len = len; res_d->ipsec_xform.direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS; if (res_d->aead) { @@ -1069,19 +1038,27 @@ test_ipsec_iph6_hdr_validate(const struct rte_ipv6_hdr *iph6, } int -test_ipsec_post_process(struct rte_mbuf *m, const struct ipsec_test_data *td, +test_ipsec_post_process(const struct rte_mbuf *m, const struct ipsec_test_data *td, struct ipsec_test_data *res_d, bool silent, const struct ipsec_test_flags *flags) { - uint8_t *output_text = rte_pktmbuf_mtod(m, uint8_t *); + uint32_t len = rte_pktmbuf_pkt_len(m); + uint8_t output_text[IPSEC_TEXT_MAX_LEN]; + const uint8_t *output; int ret; + /* Copy mbuf payload to continuous buffer */ + output = rte_pktmbuf_read(m, 0, len, output_text); + if (output != output_text) + /* Single segment mbuf, copy manually */ + memcpy(output_text, output, len); + if (td->ipsec_xform.direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS) { const struct rte_ipv4_hdr *iph4; const struct rte_ipv6_hdr *iph6; if (flags->iv_gen) { - ret = test_ipsec_iv_verify_push(m, td); + ret = test_ipsec_iv_verify_push(output_text, td); if (ret != TEST_SUCCESS) return ret; } @@ -1181,9 +1158,9 @@ test_ipsec_post_process(struct rte_mbuf *m, const struct ipsec_test_data *td, */ if (res_d == NULL) - return test_ipsec_td_verify(m, td, silent, flags); + return test_ipsec_td_verify(output_text, len, m->ol_flags, td, silent, flags); else - return test_ipsec_res_d_prepare(m, td, res_d); + return test_ipsec_res_d_prepare(output_text, len, td, res_d); } int diff --git a/app/test/test_cryptodev_security_ipsec.h b/app/test/test_cryptodev_security_ipsec.h index e55961dd1f..92e641ba0b 100644 --- a/app/test/test_cryptodev_security_ipsec.h +++ b/app/test/test_cryptodev_security_ipsec.h @@ -109,6 +109,7 @@ struct ipsec_test_flags { bool dec_ttl_or_hop_limit; bool ah; uint32_t plaintext_len; + int nb_segs_in_mbuf; }; struct crypto_param { @@ -288,7 +289,7 @@ void test_ipsec_td_update(struct ipsec_test_data td_inb[], void test_ipsec_display_alg(const struct crypto_param *param1, const struct crypto_param *param2); -int test_ipsec_post_process(struct rte_mbuf *m, +int test_ipsec_post_process(const struct rte_mbuf *m, const struct ipsec_test_data *td, struct ipsec_test_data *res_d, bool silent, const struct ipsec_test_flags *flags);