|
135 | 135 | #endif |
136 | 136 | extern void wc_linuxkm_relax_long_loop(void); |
137 | 137 |
|
| 138 | + enum wc_svr_flags { |
| 139 | + WC_SVR_FLAG_INHIBIT = 1, |
| 140 | + }; |
| 141 | + |
| 142 | + #if defined(WOLFSSL_AESNI) || defined(USE_INTEL_SPEEDUP) || \ |
| 143 | + defined(WOLFSSL_SP_X86_64_ASM) |
| 144 | + #ifndef CONFIG_X86 |
| 145 | + #error X86 SIMD extensions requested, but CONFIG_X86 is not set. |
| 146 | + #endif |
| 147 | + #define WOLFSSL_LINUXKM_SIMD |
| 148 | + #define WOLFSSL_LINUXKM_SIMD_X86 |
| 149 | + #ifndef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS |
| 150 | + #define WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS |
| 151 | + #endif |
| 152 | + #elif defined(WOLFSSL_ARMASM) || defined(WOLFSSL_SP_ARM32_ASM) || \ |
| 153 | + defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM_THUMB_ASM) ||\ |
| 154 | + defined(WOLFSSL_SP_ARM_CORTEX_M_ASM) |
| 155 | + #if !defined(CONFIG_ARM) && !defined(CONFIG_ARM64) |
| 156 | + #error ARM SIMD extensions requested, but CONFIG_ARM* is not set. |
| 157 | + #endif |
| 158 | + #define WOLFSSL_LINUXKM_SIMD |
| 159 | + #define WOLFSSL_LINUXKM_SIMD_ARM |
| 160 | + #ifndef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS |
| 161 | + #define WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS |
| 162 | + #endif |
| 163 | + #else |
| 164 | + #ifndef WOLFSSL_NO_ASM |
| 165 | + #define WOLFSSL_NO_ASM |
| 166 | + #endif |
| 167 | + #endif |
| 168 | + |
138 | 169 | #ifdef BUILDING_WOLFSSL |
139 | 170 |
|
140 | 171 | #if ((LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0)) || \ |
|
408 | 439 | #endif /* !__PIE__ */ |
409 | 440 | #endif /* LINUXKM_LKCAPI_REGISTER */ |
410 | 441 |
|
411 | | - #if defined(WOLFSSL_AESNI) || defined(USE_INTEL_SPEEDUP) || \ |
412 | | - defined(WOLFSSL_SP_X86_64_ASM) |
413 | | - #ifndef CONFIG_X86 |
414 | | - #error X86 SIMD extensions requested, but CONFIG_X86 is not set. |
415 | | - #endif |
416 | | - #define WOLFSSL_LINUXKM_SIMD |
417 | | - #define WOLFSSL_LINUXKM_SIMD_X86 |
418 | | - #ifndef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS |
419 | | - #define WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS |
420 | | - #endif |
421 | | - #elif defined(WOLFSSL_ARMASM) || defined(WOLFSSL_SP_ARM32_ASM) || \ |
422 | | - defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM_THUMB_ASM) ||\ |
423 | | - defined(WOLFSSL_SP_ARM_CORTEX_M_ASM) |
424 | | - #if !defined(CONFIG_ARM) && !defined(CONFIG_ARM64) |
425 | | - #error ARM SIMD extensions requested, but CONFIG_ARM* is not set. |
426 | | - #endif |
427 | | - #define WOLFSSL_LINUXKM_SIMD |
428 | | - #define WOLFSSL_LINUXKM_SIMD_ARM |
429 | | - #ifndef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS |
430 | | - #define WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS |
431 | | - #endif |
432 | | - #else |
433 | | - #ifndef WOLFSSL_NO_ASM |
434 | | - #define WOLFSSL_NO_ASM |
435 | | - #endif |
436 | | - #endif |
437 | | - |
438 | 442 | #ifndef WC_CHECK_FOR_INTR_SIGNALS |
439 | 443 | #define WC_CHECK_FOR_INTR_SIGNALS() wc_linuxkm_check_for_intr_signals() |
440 | 444 | #endif |
|
453 | 457 | #if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && \ |
454 | 458 | defined(CONFIG_X86) |
455 | 459 |
|
456 | | - enum wc_svr_flags { |
457 | | - WC_SVR_FLAG_INHIBIT = 1, |
458 | | - }; |
459 | | - |
460 | 460 | extern __must_check int allocate_wolfcrypt_linuxkm_fpu_states(void); |
461 | 461 | extern void free_wolfcrypt_linuxkm_fpu_states(void); |
462 | | - extern __must_check int can_save_vector_registers_x86(void); |
463 | | - extern __must_check int save_vector_registers_x86(enum wc_svr_flags flags); |
464 | | - extern void restore_vector_registers_x86(void); |
| 462 | + WOLFSSL_API __must_check int wc_can_save_vector_registers_x86(void); |
| 463 | + WOLFSSL_API __must_check int wc_save_vector_registers_x86(enum wc_svr_flags flags); |
| 464 | + WOLFSSL_API void wc_restore_vector_registers_x86(void); |
465 | 465 |
|
466 | 466 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0) |
467 | 467 | #include <asm/i387.h> |
|
471 | 471 | #endif |
472 | 472 | #ifndef CAN_SAVE_VECTOR_REGISTERS |
473 | 473 | #ifdef DEBUG_VECTOR_REGISTER_ACCESS_FUZZING |
474 | | - #define CAN_SAVE_VECTOR_REGISTERS() (can_save_vector_registers_x86() && (SAVE_VECTOR_REGISTERS2_fuzzer() == 0)) |
| 474 | + #define CAN_SAVE_VECTOR_REGISTERS() (wc_can_save_vector_registers_x86() && (SAVE_VECTOR_REGISTERS2_fuzzer() == 0)) |
475 | 475 | #else |
476 | | - #define CAN_SAVE_VECTOR_REGISTERS() can_save_vector_registers_x86() |
| 476 | + #define CAN_SAVE_VECTOR_REGISTERS() wc_can_save_vector_registers_x86() |
477 | 477 | #endif |
478 | 478 | #endif |
479 | 479 | #ifndef SAVE_VECTOR_REGISTERS |
480 | 480 | #define SAVE_VECTOR_REGISTERS(fail_clause) { \ |
481 | | - int _svr_ret = save_vector_registers_x86(0); \ |
| 481 | + int _svr_ret = wc_save_vector_registers_x86(0); \ |
482 | 482 | if (_svr_ret != 0) { \ |
483 | 483 | fail_clause \ |
484 | 484 | } \ |
|
489 | 489 | #define SAVE_VECTOR_REGISTERS2() ({ \ |
490 | 490 | int _fuzzer_ret = SAVE_VECTOR_REGISTERS2_fuzzer(); \ |
491 | 491 | (_fuzzer_ret == 0) ? \ |
492 | | - save_vector_registers_x86(0) : \ |
| 492 | + wc_save_vector_registers_x86(0) : \ |
493 | 493 | _fuzzer_ret; \ |
494 | 494 | }) |
495 | 495 | #else |
496 | | - #define SAVE_VECTOR_REGISTERS2() save_vector_registers_x86(0) |
| 496 | + #define SAVE_VECTOR_REGISTERS2() wc_save_vector_registers_x86(0) |
497 | 497 | #endif |
498 | 498 | #endif |
499 | 499 | #ifndef RESTORE_VECTOR_REGISTERS |
500 | | - #define RESTORE_VECTOR_REGISTERS() restore_vector_registers_x86() |
| 500 | + #define RESTORE_VECTOR_REGISTERS() wc_restore_vector_registers_x86() |
501 | 501 | #endif |
502 | 502 |
|
503 | 503 | #ifndef DISABLE_VECTOR_REGISTERS |
504 | | - #define DISABLE_VECTOR_REGISTERS() save_vector_registers_x86(WC_SVR_FLAG_INHIBIT) |
| 504 | + #define DISABLE_VECTOR_REGISTERS() wc_save_vector_registers_x86(WC_SVR_FLAG_INHIBIT) |
505 | 505 | #endif |
506 | 506 | #ifndef REENABLE_VECTOR_REGISTERS |
507 | | - #define REENABLE_VECTOR_REGISTERS() restore_vector_registers_x86() |
| 507 | + #define REENABLE_VECTOR_REGISTERS() wc_restore_vector_registers_x86() |
508 | 508 | #endif |
509 | 509 |
|
510 | 510 | #elif defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && (defined(CONFIG_ARM) || defined(CONFIG_ARM64)) |
|
544 | 544 | #endif |
545 | 545 |
|
546 | 546 | #elif defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) |
547 | | - #error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unsupported architecture. |
| 547 | + #error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture. |
548 | 548 | #endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */ |
549 | 549 |
|
550 | 550 | _Pragma("GCC diagnostic pop"); |
|
765 | 765 |
|
766 | 766 | #ifdef CONFIG_X86 |
767 | 767 | typeof(allocate_wolfcrypt_linuxkm_fpu_states) *allocate_wolfcrypt_linuxkm_fpu_states; |
768 | | - typeof(can_save_vector_registers_x86) *can_save_vector_registers_x86; |
| 768 | + typeof(wc_can_save_vector_registers_x86) *wc_can_save_vector_registers_x86; |
769 | 769 | typeof(free_wolfcrypt_linuxkm_fpu_states) *free_wolfcrypt_linuxkm_fpu_states; |
770 | | - typeof(restore_vector_registers_x86) *restore_vector_registers_x86; |
771 | | - typeof(save_vector_registers_x86) *save_vector_registers_x86; |
| 770 | + typeof(wc_restore_vector_registers_x86) *wc_restore_vector_registers_x86; |
| 771 | + typeof(wc_save_vector_registers_x86) *wc_save_vector_registers_x86; |
772 | 772 | #else /* !CONFIG_X86 */ |
773 | | - #error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unsupported architecture. |
| 773 | + #error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture. |
774 | 774 | #endif /* arch */ |
775 | 775 |
|
776 | 776 | #endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */ |
|
1046 | 1046 |
|
1047 | 1047 | #if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && defined(CONFIG_X86) |
1048 | 1048 | #define allocate_wolfcrypt_linuxkm_fpu_states WC_LKM_INDIRECT_SYM(allocate_wolfcrypt_linuxkm_fpu_states) |
1049 | | - #define can_save_vector_registers_x86 WC_LKM_INDIRECT_SYM(can_save_vector_registers_x86) |
| 1049 | + #define wc_can_save_vector_registers_x86 WC_LKM_INDIRECT_SYM(wc_can_save_vector_registers_x86) |
1050 | 1050 | #define free_wolfcrypt_linuxkm_fpu_states WC_LKM_INDIRECT_SYM(free_wolfcrypt_linuxkm_fpu_states) |
1051 | | - #define restore_vector_registers_x86 WC_LKM_INDIRECT_SYM(restore_vector_registers_x86) |
1052 | | - #define save_vector_registers_x86 WC_LKM_INDIRECT_SYM(save_vector_registers_x86) |
| 1051 | + #define wc_restore_vector_registers_x86 WC_LKM_INDIRECT_SYM(wc_restore_vector_registers_x86) |
| 1052 | + #define wc_save_vector_registers_x86 WC_LKM_INDIRECT_SYM(wc_save_vector_registers_x86) |
1053 | 1053 | #elif defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) |
1054 | | - #error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unsupported architecture. |
| 1054 | + #error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture. |
1055 | 1055 | #endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */ |
1056 | 1056 |
|
1057 | 1057 | #define __mutex_init WC_LKM_INDIRECT_SYM(__mutex_init) |
|
1179 | 1179 |
|
1180 | 1180 | #endif /* BUILDING_WOLFSSL */ |
1181 | 1181 |
|
| 1182 | + #if !defined(BUILDING_WOLFSSL) |
| 1183 | + /* some caller code needs these. */ |
| 1184 | + #if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) |
| 1185 | + #if defined(CONFIG_X86) |
| 1186 | + WOLFSSL_API __must_check int wc_can_save_vector_registers_x86(void); |
| 1187 | + WOLFSSL_API __must_check int wc_save_vector_registers_x86(enum wc_svr_flags flags); |
| 1188 | + WOLFSSL_API void wc_restore_vector_registers_x86(void); |
| 1189 | + #ifndef DISABLE_VECTOR_REGISTERS |
| 1190 | + #define DISABLE_VECTOR_REGISTERS() wc_save_vector_registers_x86(WC_SVR_FLAG_INHIBIT) |
| 1191 | + #endif |
| 1192 | + #ifndef REENABLE_VECTOR_REGISTERS |
| 1193 | + #define REENABLE_VECTOR_REGISTERS() wc_restore_vector_registers_x86() |
| 1194 | + #endif |
| 1195 | + #else /* !CONFIG_X86 */ |
| 1196 | + #error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture. |
| 1197 | + #endif /* !CONFIG_X86 */ |
| 1198 | + #endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */ |
| 1199 | + #endif /* !BUILDING_WOLFSSL */ |
| 1200 | + |
1182 | 1201 | /* Copied from wc_port.h: For FIPS keep the function names the same */ |
1183 | 1202 | #ifdef HAVE_FIPS |
1184 | 1203 | #define wc_InitMutex InitMutex |
|
1232 | 1251 | return 0; |
1233 | 1252 | } |
1234 | 1253 | #else |
| 1254 | + /* if BUILDING_WOLFSSL, spinlock.h will have already been included |
| 1255 | + * recursively above, with the bevy of warnings suppressed, and the |
| 1256 | + * below include will be a redundant no-op. |
| 1257 | + */ |
| 1258 | + #include <linux/spinlock.h> |
| 1259 | + |
1235 | 1260 | typedef struct wolfSSL_Mutex { |
1236 | 1261 | spinlock_t lock; |
1237 | 1262 | unsigned long irq_flags; |
|
0 commit comments