crypto-native: properly deal with broken or outdated toolchains

Avoids crash due to missing symbol, when build system detects toolchain
which is not able to produce binaries for all targets we need....

Type: fix

Change-Id: I77ee63cb8dca3c9e4e83a6235c60f1439a472444
Signed-off-by: Damjan Marion <damarion@cisco.com>
This commit is contained in:
Damjan Marion
2020-05-11 14:03:29 +02:00
parent 1ae16c8f3b
commit 73a60b2da4
5 changed files with 53 additions and 41 deletions

View File

@@ -12,13 +12,13 @@
# limitations under the License.
if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
list(APPEND VARIANTS "sse42\;-march=silvermont")
list(APPEND VARIANTS "avx2\;-march=core-avx2")
if(compiler_flag_march_skylake_avx512)
list(APPEND VARIANTS "avx512\;-march=skylake-avx512")
list(APPEND VARIANTS "slm\;-march=silvermont")
list(APPEND VARIANTS "hsw\;-march=haswell")
if(compiler_flag_march_skylake_avx512 AND compiler_flag_mprefer_vector_width)
list(APPEND VARIANTS "skx\;-march=skylake-avx512 -mprefer-vector-width=256")
endif()
if(compiler_flag_march_icelake_client)
list(APPEND VARIANTS "vaesni\;-march=icelake-client")
if(compiler_flag_march_icelake_client AND compiler_flag_mprefer_vector_width)
list(APPEND VARIANTS "icl\;-march=icelake-client -mprefer-vector-width=512")
endif()
set (COMPILE_FILES aes_cbc.c aes_gcm.c)
set (COMPILE_OPTS -Wall -fno-common -maes)
@@ -42,6 +42,7 @@ foreach(VARIANT ${VARIANTS})
set(l crypto_native_${v})
add_library(${l} OBJECT ${COMPILE_FILES})
set_target_properties(${l} PROPERTIES POSITION_INDEPENDENT_CODE ON)
separate_arguments(f)
target_compile_options(${l} PUBLIC ${f} ${COMPILE_OPTS})
target_sources(crypto_native_plugin PRIVATE $<TARGET_OBJECTS:${l}>)
endforeach()

View File

@@ -474,15 +474,15 @@ foreach_aes_cbc_handler_type;
clib_error_t *
#ifdef __VAES__
crypto_native_aes_cbc_init_vaes (vlib_main_t * vm)
crypto_native_aes_cbc_init_icl (vlib_main_t * vm)
#elif __AVX512F__
crypto_native_aes_cbc_init_avx512 (vlib_main_t * vm)
crypto_native_aes_cbc_init_skx (vlib_main_t * vm)
#elif __aarch64__
crypto_native_aes_cbc_init_neon (vlib_main_t * vm)
#elif __AVX2__
crypto_native_aes_cbc_init_avx2 (vlib_main_t * vm)
crypto_native_aes_cbc_init_hsw (vlib_main_t * vm)
#else
crypto_native_aes_cbc_init_sse42 (vlib_main_t * vm)
crypto_native_aes_cbc_init_slm (vlib_main_t * vm)
#endif
{
crypto_native_main_t *cm = &crypto_native_main;

View File

@@ -1196,15 +1196,15 @@ foreach_aes_gcm_handler_type;
clib_error_t *
#ifdef __VAES__
crypto_native_aes_gcm_init_vaes (vlib_main_t * vm)
crypto_native_aes_gcm_init_icl (vlib_main_t * vm)
#elif __AVX512F__
crypto_native_aes_gcm_init_avx512 (vlib_main_t * vm)
crypto_native_aes_gcm_init_skx (vlib_main_t * vm)
#elif __AVX2__
crypto_native_aes_gcm_init_avx2 (vlib_main_t * vm)
crypto_native_aes_gcm_init_hsw (vlib_main_t * vm)
#elif __aarch64__
crypto_native_aes_gcm_init_neon (vlib_main_t * vm)
#else
crypto_native_aes_gcm_init_sse42 (vlib_main_t * vm)
crypto_native_aes_gcm_init_slm (vlib_main_t * vm)
#endif
{
crypto_native_main_t *cm = &crypto_native_main;

View File

@@ -36,17 +36,15 @@ typedef struct
extern crypto_native_main_t crypto_native_main;
clib_error_t *crypto_native_aes_cbc_init_sse42 (vlib_main_t * vm);
clib_error_t *crypto_native_aes_cbc_init_avx2 (vlib_main_t * vm);
clib_error_t *crypto_native_aes_cbc_init_avx512 (vlib_main_t * vm);
clib_error_t *crypto_native_aes_cbc_init_vaes (vlib_main_t * vm);
clib_error_t *crypto_native_aes_cbc_init_neon (vlib_main_t * vm);
#define foreach_crypto_native_march_variant _(slm) _(hsw) _(skx) _(icl) _(neon)
#define _(v) \
clib_error_t __clib_weak *crypto_native_aes_cbc_init_##v (vlib_main_t * vm); \
clib_error_t __clib_weak *crypto_native_aes_gcm_init_##v (vlib_main_t * vm); \
foreach_crypto_native_march_variant;
#undef _
clib_error_t *crypto_native_aes_gcm_init_sse42 (vlib_main_t * vm);
clib_error_t *crypto_native_aes_gcm_init_avx2 (vlib_main_t * vm);
clib_error_t *crypto_native_aes_gcm_init_avx512 (vlib_main_t * vm);
clib_error_t *crypto_native_aes_gcm_init_vaes (vlib_main_t * vm);
clib_error_t *crypto_native_aes_gcm_init_neon (vlib_main_t * vm);
#endif /* __crypto_native_h__ */
/*

View File

@@ -77,39 +77,52 @@ crypto_native_init (vlib_main_t * vm)
vnet_crypto_register_engine (vm, "native", 100,
"Native ISA Optimized Crypto");
if (0);
#if __x86_64__
if (clib_cpu_supports_vaes ())
error = crypto_native_aes_cbc_init_vaes (vm);
else if (clib_cpu_supports_avx512f ())
error = crypto_native_aes_cbc_init_avx512 (vm);
else if (clib_cpu_supports_avx2 ())
error = crypto_native_aes_cbc_init_avx2 (vm);
else if (crypto_native_aes_cbc_init_icl && clib_cpu_supports_vaes ())
error = crypto_native_aes_cbc_init_icl (vm);
else if (crypto_native_aes_cbc_init_skx && clib_cpu_supports_avx512f ())
error = crypto_native_aes_cbc_init_skx (vm);
else if (crypto_native_aes_cbc_init_hsw && clib_cpu_supports_avx2 ())
error = crypto_native_aes_cbc_init_hsw (vm);
else if (crypto_native_aes_cbc_init_slm)
error = crypto_native_aes_cbc_init_slm (vm);
#endif
#if __aarch64__
else if (crypto_native_aes_cbc_init_neon)
error = crypto_native_aes_cbc_init_neon (vm);
#endif
else
error = crypto_native_aes_cbc_init_sse42 (vm);
error = clib_error_return (0, "No AES CBC implemenation available");
if (error)
goto error;
#if __x86_64__
if (clib_cpu_supports_pclmulqdq ())
{
if (clib_cpu_supports_vaes ())
error = crypto_native_aes_gcm_init_vaes (vm);
else if (clib_cpu_supports_avx512f ())
error = crypto_native_aes_gcm_init_avx512 (vm);
else if (clib_cpu_supports_avx2 ())
error = crypto_native_aes_gcm_init_avx2 (vm);
if (crypto_native_aes_gcm_init_icl && clib_cpu_supports_vaes ())
error = crypto_native_aes_gcm_init_icl (vm);
else if (crypto_native_aes_gcm_init_skx && clib_cpu_supports_avx512f ())
error = crypto_native_aes_gcm_init_skx (vm);
else if (crypto_native_aes_gcm_init_hsw && clib_cpu_supports_avx2 ())
error = crypto_native_aes_gcm_init_hsw (vm);
else if (crypto_native_aes_gcm_init_slm)
error = crypto_native_aes_gcm_init_slm (vm);
else
error = crypto_native_aes_gcm_init_sse42 (vm);
error = clib_error_return (0, "No AES GCM implemenation available");
if (error)
goto error;
}
#endif
#if __aarch64__
if ((error = crypto_native_aes_cbc_init_neon (vm)))
goto error;
if (crypto_native_aes_gcm_init_neon)
error = crypto_native_aes_gcm_init_neon (vm);
else
error = clib_error_return (0, "No AES GCM implemenation available");
if ((error = crypto_native_aes_gcm_init_neon (vm)))
if (error)
goto error;
#endif