compile ipsec on Windows
cover compile ipsec on Windows
Removed VLA for compatibility with MSVC (which does not support VLAs). Used alloca when a constant fixed length that can be used instead is not known.
Implementation for rte_ipsec_pkt_crypto_group and rte_ipsec_ses_from_crypto was moved to new file lib\ipsec\ipsec_group.c because these functions get exported in a shared library (lib\ipsec\version.map).
Implementation for rte_ipsec_pkt_crypto_prepare and rte_ipsec_pkt_process was moved to new file lib\ipsec\ipsec.c because these functions get exported in a shared library (lib\ipsec\version.map).
Removed logic which was skipping ipsec on Windows.
Andre Muezerie (2):
lib/ipsec: compile ipsec on Windows
app/test: enable ipsec-related tests
app/test/test_ipsec.c | 17 +---- app/test/test_ipsec_perf.c | 13 ---- app/test/test_ipsec_sad.c | 13 ---- app/test/test_security_inline_proto.c | 26 -------- lib/ipsec/esp_inb.c | 57 +++++++++++----- lib/ipsec/esp_outb.c | 48 ++++++++++---- lib/ipsec/ipsec.c | 19 ++++++ lib/ipsec/ipsec_group.c | 93 +++++++++++++++++++++++++++ lib/ipsec/ipsec_sad.c | 1 + lib/ipsec/ipsec_telemetry.c | 1 + lib/ipsec/meson.build | 10 +-- lib/ipsec/misc.h | 10 ++- lib/ipsec/rte_ipsec.h | 15 ++--- lib/ipsec/rte_ipsec_group.h | 84 ++---------------------- lib/ipsec/sa.c | 4 +- 15 files changed, 210 insertions(+), 201 deletions(-) create mode 100644 lib/ipsec/ipsec.c create mode 100644 lib/ipsec/ipsec_group.c
--
2.47.0.vfs.0.3
PATCH 1/2 lib/ipsec: compile ipsec on Windows
Removed VLA for compatibility with MSVC (which does not support VLAs). Used alloca when a constant fixed length that can be used instead is not known.
Implementation for rte_ipsec_pkt_crypto_group and rte_ipsec_ses_from_crypto was moved to new file lib\ipsec\ipsec_group.c because these functions get exported in a shared library (lib\ipsec\version.map).
Implementation for rte_ipsec_pkt_crypto_prepare and rte_ipsec_pkt_process was moved to new file lib\ipsec\ipsec.c because these functions get exported in a shared library (lib\ipsec\version.map).
Removed code in meson.build which was skipping ipsec on Windows.
--- lib/ipsec/esp_inb.c | 57 ++++++++++++++++------- lib/ipsec/esp_outb.c | 48 +++++++++++++------ lib/ipsec/ipsec.c | 19 ++++++++ lib/ipsec/ipsec_group.c | 93 +++++++++++++++++++++++++++++++++++++ lib/ipsec/ipsec_sad.c | 1 + lib/ipsec/ipsec_telemetry.c | 1 + lib/ipsec/meson.build | 10 +--- lib/ipsec/misc.h | 10 ++-- lib/ipsec/rte_ipsec.h | 15 ++---- lib/ipsec/rte_ipsec_group.h | 84 ++------------------------------- lib/ipsec/sa.c | 4 +- 11 files changed, 208 insertions(+), 134 deletions(-) create mode 100644 lib/ipsec/ipsec.c create mode 100644 lib/ipsec/ipsec_group.c
lib/ipsec/esp_inb.c +40 -17
@@ -370,8 +370,9 @@ esp_inb_pkt_prepare(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[],struct rte_cryptodev_sym_session *cs;struct replay_sqn *rsn;union sym_op_data icv; -uint32_t dr[num]; +uint32_t *dr; + dr =alloca (sizeof (uint32_t ) * num); sa = ss->sa; cs = ss->crypto.ses; rsn =rsn_acquire (sa);
@@ -576,12 +577,16 @@ tun_process(struct rte_ipsec_sa *sa, struct rte_mbuf *mb[], uint32_t sqn[], uint32_t dr[], uint16_t num, uint8_t sqh_len) { uint32_t adj, i, k, tl, bytes; -uint32_t hl[num], to[num]; -struct rte_esp_tail espt[num]; -struct rte_mbuf *ml[num]; +uint32_t *hl, *to; +struct rte_esp_tail *espt; +struct rte_mbuf **ml;const void *outh;void *inh; + hl =alloca (sizeof (uint32_t ) * num); + to =alloca (sizeof (uint32_t ) * num); + espt =alloca (sizeof (struct rte_esp_tail ) * num); + ml =alloca (sizeof (struct rte_mbuf *) * num);/* * remove icv, esp trailer and high-order * 32 bits of esn from packet length
@@ -640,10 +645,14 @@ trs_process(struct rte_ipsec_sa *sa, struct rte_mbuf *mb[], {char *np;uint32_t i, k, l2, tl, bytes; -uint32_t hl[num], to[num]; -struct rte_esp_tail espt[num]; -struct rte_mbuf *ml[num]; - +uint32_t *hl, *to; +struct rte_esp_tail *espt; +struct rte_mbuf **ml; + + hl =alloca (sizeof (uint32_t ) * num); + to =alloca (sizeof (uint32_t ) * num); + espt =alloca (sizeof (struct rte_esp_tail ) * num); + ml =alloca (sizeof (struct rte_mbuf *) * num);/* * remove icv, esp trailer and high-order * 32 bits of esn from packet length
@@ -724,8 +733,11 @@ esp_inb_pkt_process(struct rte_ipsec_sa *sa, struct rte_mbuf *mb[], uint16_t num, uint8_t sqh_len, esp_inb_process_t process) { uint32_t k, n; -uint32_t sqn[num]; -uint32_t dr[num]; +uint32_t *sqn; +uint32_t *dr; + + sqn =alloca (sizeof (uint32_t ) * num); + dr =alloca (sizeof (uint32_t ) * num);/* process packets, extract seq numbers */ k =process (sa, mb, sqn, dr, num, sqh_len);
@@ -760,13 +772,24 @@ cpu_inb_pkt_prepare(const struct rte_ipsec_session *ss,struct rte_ipsec_sa *sa;struct replay_sqn *rsn;union sym_op_data icv; -struct rte_crypto_va_iova_ptr iv[num]; -struct rte_crypto_va_iova_ptr aad[num]; -struct rte_crypto_va_iova_ptr dgst[num]; -uint32_t dr[num]; -uint32_t l4ofs[num]; -uint32_t clen[num]; -uint64_t ivbuf[num][IPSEC_MAX_IV_QWORD ]; +struct rte_crypto_va_iova_ptr *iv; +struct rte_crypto_va_iova_ptr *aad; +struct rte_crypto_va_iova_ptr *dgst; +uint32_t *dr; +uint32_t *l4ofs; +uint32_t *clen; +uint64_t **ivbuf; + + iv =alloca (sizeof (struct rte_crypto_va_iova_ptr ) * num); + aad =alloca (sizeof (struct rte_crypto_va_iova_ptr ) * num); + dgst =alloca (sizeof (struct rte_crypto_va_iova_ptr ) * num); + dr =alloca (sizeof (uint32_t ) * num); + l4ofs =alloca (sizeof (uint32_t ) * num); + clen =alloca (sizeof (uint32_t ) * num); + + ivbuf =alloca (sizeof (uint64_t *) * num); +for (i =0 ; i < num; i++) + ivbuf[i] =alloca (sizeof (uint64_t ) *IPSEC_MAX_IV_QWORD ); sa = ss->sa;
lib/ipsec/esp_outb.c +34 -14
98 lines not on this page · raw message
lib/ipsec/ipsec.c new file +19 -0
@@ -0,0 +1,19 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright(c) 2018-2020 Intel Corporation +*/ + +#include "rte_ipsec.h" + +uint16_t +rte_ipsec_pkt_crypto_prepare (const struct rte_ipsec_session *ss, +struct rte_mbuf *mb[],struct rte_crypto_op *cop[],uint16_t num) +{ +return ss->pkt_func.prepare.async (ss, mb, cop, num); +} + +uint16_t +rte_ipsec_pkt_process (const struct rte_ipsec_session *ss,struct rte_mbuf *mb[], +uint16_t num) +{ +return ss->pkt_func.process (ss, mb, num); +}
lib/ipsec/ipsec_group.c new file +93 -0
93 lines not on this page · raw message
lib/ipsec/ipsec_sad.c +1 -0
@@ -3,6 +3,7 @@*/ #include <string.h> +#include <sys/queue.h> #include <rte_eal_memconfig.h> #include <rte_errno.h>
lib/ipsec/ipsec_telemetry.c +1 -0
@@ -3,6 +3,7 @@*/ #include <stdlib.h> +#include <sys/queue.h> #include <rte_ipsec.h> #include <rte_telemetry.h> #include <rte_malloc.h>
lib/ipsec/meson.build +2 -8
@@ -1,15 +1,9 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2018 Intel Corporation -if is_windows - build = false - reason = 'not supported on Windows' - subdir_done() -endif - sources = files('esp_inb.c', 'esp_outb.c', - 'sa.c', 'ses.c', 'ipsec_sad.c', - 'ipsec_telemetry.c') + 'ipsec.c', 'ipsec_group.c', 'ipsec_sad.c', + 'ipsec_telemetry.c', 'sa.c', 'ses.c') headers = files('rte_ipsec.h', 'rte_ipsec_sa.h', 'rte_ipsec_sad.h') indirect_headers += files('rte_ipsec_group.h')
lib/ipsec/misc.h +7 -3
@@ -20,10 +20,11 @@ move_bad_mbufs(struct rte_mbuf *mb[], const uint32_t bad_idx[], uint32_t nb_mb, uint32_t nb_bad) {uint32_t i, j, k; -struct rte_mbuf *drb[nb_bad]; +struct rte_mbuf **drb; j =0 ; k =0 ; + drb =alloca (sizeof (struct rte_mbuf *) * nb_bad);/* copy bad ones into a temp place */ for (i =0 ; i != nb_mb; i++) {
@@ -119,8 +120,8 @@ cpu_crypto_bulk(const struct rte_ipsec_session *ss, {uint32_t i, j, n;int32_t vcnt, vofs; -int32_t st[num]; -struct rte_crypto_sgl vecpkt[num]; +int32_t *st; +struct rte_crypto_sgl *vecpkt;struct rte_crypto_vec vec[UINT8_MAX ];struct rte_crypto_sym_vec symvec;
@@ -128,6 +129,9 @@ cpu_crypto_bulk(const struct rte_ipsec_session *ss, j =0 , n =0 ; vofs =0 ; + st =alloca (sizeof (int32_t ) * num); + vecpkt =alloca (sizeof (struct rte_crypto_sgl ) * num); +for (i =0 ; i != num; i++) { vcnt = rte_crypto_mbuf_to_vec(mb[i], l4ofs[i], clen[i],
lib/ipsec/rte_ipsec.h +4 -11
@@ -134,12 +134,9 @@ rte_ipsec_session_prepare(struct rte_ipsec_session *ss);* @return * Number of successfully processed packets, with error code set in rte_errno. */ -static inline uint16_t +uint16_t rte_ipsec_pkt_crypto_prepare (const struct rte_ipsec_session *ss, -struct rte_mbuf *mb[],struct rte_crypto_op *cop[],uint16_t num) -{ -return ss->pkt_func.prepare.async (ss, mb, cop, num); -} +struct rte_mbuf *mb[],struct rte_crypto_op *cop[],uint16_t num); static inline uint16_t rte_ipsec_pkt_cpu_prepare(const struct rte_ipsec_session *ss,
@@ -231,13 +228,9 @@ rte_ipsec_pkt_cpu_prepare_stateless(const struct rte_ipsec_session *ss,* @return * Number of successfully processed packets, with error code set in rte_errno. */ -static inline uint16_t +uint16_t rte_ipsec_pkt_process (const struct rte_ipsec_session *ss,struct rte_mbuf *mb[], -uint16_t num) -{ -return ss->pkt_func.process (ss, mb, num); -} - +uint16_t num);/** * Enable per SA telemetry for a specific SA.
lib/ipsec/rte_ipsec_group.h +4 -80
97 lines not on this page · raw message
lib/ipsec/sa.c +3 -1
@@ -7,6 +7,7 @@#include <rte_ip.h> #include <rte_udp.h> #include <rte_errno.h> +#include <rte_os_shim.h> #include "sa.h" #include "ipsec_sqn.h"
@@ -655,8 +656,9 @@ pkt_flag_process(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[], uint16_t num) { uint32_t i, k, bytes; -uint32_t dr[num]; +uint32_t *dr; + dr =alloca (sizeof (uint32_t ) * num);RTE_SET_USED (ss); k =0 ;
Signature · 1 line
2.47.0.vfs.0.3
RE: [PATCH 1/2] lib/ipsec: compile ipsec on Windows
Quoted 11 lines
Removed VLA for compatibility with MSVC (which does not support VLAs). Used alloca when a constant fixed length that can be used instead is not known.
Implementation for
rte_ipsec_pkt_crypto_groupandrte_ipsec_ses_from_cryptowas moved to new file lib\ipsec\ipsec_group.c because these functions get exported in a shared library (lib\ipsec\version.map).
Quoted 4 lines
Implementation for
rte_ipsec_pkt_crypto_prepareandrte_ipsec_pkt_processwas moved to new file lib\ipsec\ipsec.c because these functions get exported in a shared library (lib\ipsec\version.map).
Hmm... not sure I understood the rationale.
To me making inline functions not-inline first of all means ABI/API breakage, plus it most likely will make things slower.
RE: [PATCH 1/2] lib/ipsec: compile ipsec on Windows
In reply to Andre MuezerieQuoted 6 lines
Removed VLA for compatibility with MSVC (which does not support VLAs). Used alloca when a constant fixed length that can be used instead is not known.
...
Quoted 2 lines
Signed-off-by Andre Muezerie <[email protected]>---
...
lib/ipsec/esp_inb.c esp_inb_pkt_prepare(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[], · line 373
Quoted 10 lines
lib/ipsec/esp_inb.c +1
-1@@ -370,8 +370,9 @@ esp_inb_pkt_prepare(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[],struct rte_cryptodev_sym_session *cs;struct replay_sqn *rsn;union sym_op_data icv; -uint32_t dr[num]; +uint32_t *dr;
I understand the intention, but obviously as the lib maintainer, I am no very happy with mechanic replacement of VLAs with alloca() calls.
Again, while it helps to make MSVC happy, it doesn't really solve a potential problem with using VLAs here - I we can end-up with stack overflowed if someone will call one of these functions with input arrays of huge size.
It would be much better to re-work the internal functions to work over fixed-size array an then call them in a loop.
The main issue here is that by API convention we need to re-arrange input array by moving bad (not processed) mbuf after the good ones.
But even with that splitting processing into multiple iterations over small chunks might help I think.
Quoted 24 lines
lib/ipsec/esp_inb.c +8
-3+ dr =alloca (sizeof (uint32_t ) * num); sa = ss->sa; cs = ss->crypto.ses; rsn =rsn_acquire (sa);@@ -576,12 +577,16 @@ tun_process(struct rte_ipsec_sa *sa, struct rte_mbuf *mb[], uint32_t sqn[], uint32_t dr[], uint16_t num, uint8_t sqh_len) { uint32_t adj, i, k, tl, bytes; -uint32_t hl[num], to[num]; -struct rte_esp_tail espt[num]; -struct rte_mbuf *ml[num]; +uint32_t *hl, *to; +struct rte_esp_tail *espt; +struct rte_mbuf **ml;const void *outh;void *inh; + hl =alloca (sizeof (uint32_t ) * num); + to =alloca (sizeof (uint32_t ) * num); + espt =alloca (sizeof (struct rte_esp_tail ) * num); + ml =alloca (sizeof (struct rte_mbuf *) * num);/* * remove icv, esp trailer and high-order * 32 bits of esn from packet length
Re: [PATCH 1/2] lib/ipsec: compile ipsec on Windows
Quoted 27 lines · Konstantin Ananyev
Quoted 6 lines
Removed VLA for compatibility with MSVC (which does not support VLAs). Used alloca when a constant fixed length that can be used instead is not known.
...
Quoted 2 lines
Signed-off-by Andre Muezerie <[email protected]>---
...
lib/ipsec/esp_inb.c esp_inb_pkt_prepare(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[], · line 373
Quoted 10 lines
lib/ipsec/esp_inb.c +1
-1@@ -370,8 +370,9 @@ esp_inb_pkt_prepare(const struct rte_ipsec_session *ss, struct rte_mbuf *mb[],struct rte_cryptodev_sym_session *cs;struct replay_sqn *rsn;union sym_op_data icv; -uint32_t dr[num]; +uint32_t *dr;I understand the intention, but obviously as the lib maintainer, I am no very happy with mechanic replacement of VLAs with
alloca()calls. Again, while it helps to make MSVC happy, it doesn't really solve a potential problem
Quoted 8 lines
with using VLAs here - I we can end-up with stack overflowed if someone will call one of these functions with input arrays of huge size.
It would be much better to re-work the internal functions to work over fixed-size array an then call them in a loop.
The main issue here is that by API convention we need to re-arrange input array by moving bad (not processed) mbuf after the good ones.
But even with that splitting processing into multiple iterations over small chunks might help I think.
Understood. I'll focus on the other patches being reviewed and revisit this one at some other time.
Quoted 25 lines
Quoted 25 lines
lib/ipsec/esp_inb.c +8
-3+ dr =alloca (sizeof (uint32_t ) * num); sa = ss->sa; cs = ss->crypto.ses; rsn =rsn_acquire (sa);@@ -576,12 +577,16 @@ tun_process(struct rte_ipsec_sa *sa, struct rte_mbuf *mb[], uint32_t sqn[], uint32_t dr[], uint16_t num, uint8_t sqh_len) { uint32_t adj, i, k, tl, bytes; -uint32_t hl[num], to[num]; -struct rte_esp_tail espt[num]; -struct rte_mbuf *ml[num]; +uint32_t *hl, *to; +struct rte_esp_tail *espt; +struct rte_mbuf **ml;const void *outh;void *inh; + hl =alloca (sizeof (uint32_t ) * num); + to =alloca (sizeof (uint32_t ) * num); + espt =alloca (sizeof (struct rte_esp_tail ) * num); + ml =alloca (sizeof (struct rte_mbuf *) * num);/* * remove icv, esp trailer and high-order * 32 bits of esn from packet length
PATCH 2/2 app/test: enable ipsec-related tests
In reply to Andre MuezerieRemoved ifdefs which were bypassing the ipsec tests on Windows.
Removed "return" from void function to avoid warning on MSVC.
--- app/test/test_ipsec.c | 17 ++--------------- app/test/test_ipsec_perf.c | 13 ------------- app/test/test_ipsec_sad.c | 13 ------------- app/test/test_security_inline_proto.c | 26 -------------------------- 4 files changed, 2 insertions(+), 67 deletions(-)
app/test/test_ipsec.c +2 -15
@@ -17,17 +17,6 @@#include <rte_crypto.h> #include <rte_cryptodev.h> #include <rte_lcore.h> - -#ifdef RTE_EXEC_ENV_WINDOWS -static int -test_ipsec (void ) -{ -printf ("ipsec not supported on Windows, skipping test\n" ); -return TEST_SKIPPED ; -} - -#else -#include <rte_ipsec.h> #include <rte_random.h> #include <rte_esp.h>
@@ -1185,9 +1174,9 @@ destroy_session(struct ipsec_unitest_params *ut, uint8_t crypto_dev, uint32_t j) {if (ut->ss[j].type ==RTE_SECURITY_ACTION_TYPE_NONE ) -return destroy_crypto_session (ut, crypto_dev, j); +destroy_crypto_session (ut, crypto_dev, j);else -return destroy_dummy_sec_session (ut, j); +destroy_dummy_sec_session (ut, j); } static void
@@ -2615,6 +2604,4 @@ test_ipsec(void)return unit_test_suite_runner (&ipsec_testsuite); } -#endif /* !RTE_EXEC_ENV_WINDOWS */ -REGISTER_FAST_TEST (ipsec_autotest, true, true, test_ipsec);
app/test/test_ipsec_perf.c +0 -13
@@ -10,17 +10,6 @@#include <rte_ring.h> #include <rte_mbuf.h> #include <rte_cycles.h> - -#ifdef RTE_EXEC_ENV_WINDOWS -static int -test_libipsec_perf (void ) -{ -printf ("ipsec_perf not supported on Windows, skipping test\n" ); -return TEST_SKIPPED ; -} - -#else -#include <rte_ipsec.h> #include <rte_random.h>
@@ -629,6 +618,4 @@ test_libipsec_perf(void)return TEST_SUCCESS ; } -#endif /* !RTE_EXEC_ENV_WINDOWS */ -REGISTER_PERF_TEST (ipsec_perf_autotest, test_libipsec_perf);
app/test/test_ipsec_sad.c +0 -13
@@ -8,17 +8,6 @@#include <stdint.h> #include <stdlib.h> #include <string.h> - -#ifdef RTE_EXEC_ENV_WINDOWS -static int -test_ipsec_sad (void ) -{ -printf ("ipsec_sad not supported on Windows, skipping test\n" ); -return TEST_SKIPPED ; -} - -#else -#include <rte_ipsec_sad.h> #include <rte_memory.h>
@@ -897,6 +886,4 @@ test_ipsec_sad(void)return unit_test_suite_runner (&ipsec_sad_tests); } -#endif /* !RTE_EXEC_ENV_WINDOWS */ -REGISTER_TEST_COMMAND (ipsec_sad_autotest, test_ipsec_sad);
app/test/test_security_inline_proto.c +0 -26
@@ -14,30 +14,6 @@#include "test_security_inline_proto_vectors.h" #include "test_security_proto.h" -#ifdef RTE_EXEC_ENV_WINDOWS -static int -test_inline_ipsec (void ) -{ -printf ("Inline ipsec not supported on Windows, skipping test\n" ); -return TEST_SKIPPED ; -} - -static int -test_event_inline_ipsec (void ) -{ -printf ("Event inline ipsec not supported on Windows, skipping test\n" ); -return TEST_SKIPPED ; -} - -static int -test_inline_ipsec_sg (void ) -{ -printf ("Inline ipsec SG not supported on Windows, skipping test\n" ); -return TEST_SKIPPED ; -} - -#else -#include <rte_eventdev.h> #include <rte_event_eth_rx_adapter.h> #include <rte_event_eth_tx_adapter.h>
@@ -3619,8 +3595,6 @@ test_event_inline_ipsec(void)return unit_test_suite_runner (&inline_ipsec_testsuite); } -#endif /* !RTE_EXEC_ENV_WINDOWS */ -REGISTER_TEST_COMMAND (inline_ipsec_autotest, test_inline_ipsec);REGISTER_TEST_COMMAND (inline_ipsec_sg_autotest, test_inline_ipsec_sg);REGISTER_TEST_COMMAND (event_inline_ipsec_autotest, test_event_inline_ipsec);
Signature · 1 line
2.47.0.vfs.0.3