Skip to content

Commit 86adcd6

Browse files
Merge pull request wolfSSL#9048 from douzzer/20250730-linuxkm-tweaks
20250730-linuxkm-tweaks
2 parents 70af2be + 1152d61 commit 86adcd6

8 files changed

Lines changed: 306 additions & 132 deletions

File tree

.github/workflows/linuxkm.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
strategy:
1818
matrix:
1919
config: [
20-
'EXTRA_CPPFLAGS=-Werror --enable-option-checking=fatal --enable-linuxkm --enable-linuxkm-lkcapi-register=all --enable-all --enable-kyber=yes,original --enable-lms --enable-xmss --enable-dilithium --enable-experimental --enable-dual-alg-certs --disable-qt --disable-quic --with-sys-crypto-policy=no --disable-opensslextra --disable-testcert --enable-intelasm --enable-sp-asm --enable-crypttests CFLAGS="-DWOLFSSL_LINUXKM_VERBOSE_DEBUG -Wframe-larger-than=2048 -Wstack-usage=4096" --with-max-rsa-bits=16384',
21-
'EXTRA_CPPFLAGS=-Werror --enable-option-checking=fatal --enable-linuxkm --enable-linuxkm-pie --enable-reproducible-build --enable-linuxkm-lkcapi-register=all --enable-all-crypto --enable-cryptonly --enable-kyber=yes,original --enable-lms --enable-xmss --enable-dilithium --enable-experimental --disable-qt --disable-quic --with-sys-crypto-policy=no --disable-opensslextra --disable-testcert --enable-intelasm --enable-sp-asm --enable-crypttests CFLAGS="-DWOLFSSL_LINUXKM_VERBOSE_DEBUG -Wframe-larger-than=2048 -Wstack-usage=4096" --with-max-rsa-bits=16384'
20+
'EXTRA_CPPFLAGS=-Werror --enable-option-checking=fatal --enable-linuxkm --enable-linuxkm-lkcapi-register=all --enable-all --enable-kyber=yes,original --enable-lms --enable-xmss --enable-dilithium --enable-experimental --enable-dual-alg-certs --disable-qt --disable-quic --with-sys-crypto-policy=no --disable-opensslextra --disable-testcert --enable-intelasm --disable-sp-asm --enable-crypttests --enable-linuxkm-benchmarks CFLAGS="-DWOLFSSL_LINUXKM_VERBOSE_DEBUG -Wframe-larger-than=2048 -Wstack-usage=4096 -DBENCH_EMBEDDED -DBENCH_MIN_RUNTIME_SEC=0.01 -DBENCH_NTIMES=1 -DBENCH_AGREETIMES=1" --with-max-rsa-bits=16384',
21+
'EXTRA_CPPFLAGS=-Werror --enable-option-checking=fatal --enable-linuxkm --enable-linuxkm-pie --enable-reproducible-build --enable-linuxkm-lkcapi-register=all --enable-all-crypto --enable-cryptonly --enable-kyber=yes,original --enable-lms --enable-xmss --enable-dilithium --enable-experimental --disable-qt --disable-quic --with-sys-crypto-policy=no --disable-opensslextra --disable-testcert --enable-intelasm --disable-sp-asm --enable-crypttests --enable-linuxkm-benchmarks CFLAGS="-DWOLFSSL_LINUXKM_VERBOSE_DEBUG -Wframe-larger-than=2048 -Wstack-usage=4096 -DBENCH_EMBEDDED -DBENCH_MIN_RUNTIME_SEC=0.01 -DBENCH_NTIMES=1 -DBENCH_AGREETIMES=1" --with-max-rsa-bits=16384'
2222
]
2323
name: build module
2424
if: github.repository_owner == 'wolfssl'

linuxkm/Kbuild

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,15 @@ endif
304304

305305
# auto-generate the exported symbol list, leveraging the WOLFSSL_API visibility tags.
306306
# exclude symbols that don't match wc_* or wolf*.
307-
$(obj)/linuxkm/module_exports.c: $(src)/module_exports.c.template $(WOLFSSL_OBJ_TARGETS)
307+
$(obj)/linuxkm/module_exports.c: $(src)/module_exports.c.template $(WOLFSSL_OBJ_TARGETS) $(obj)/linuxkm/module_hooks.o
308308
@cp $< $@ || exit $$?
309309
if [[ "$${VERSION}" -gt 6 || ("$${VERSION}" -eq 6 && "$${PATCHLEVEL}" -ge 13) ]]; then
310310
# use ASCII octal escape to avoid syntax disruption in the awk script.
311311
ns='\042WOLFSSL\042'
312312
else
313313
ns='WOLFSSL'
314314
fi
315-
$(READELF) --symbols --wide $(WOLFSSL_OBJ_TARGETS) |
315+
$(READELF) --symbols --wide $(filter %.o,$^) |
316316
$(AWK) '/^ *[0-9]+: / {
317317
if ($$8 !~ /^(wc_|wolf|WOLF|TLSX_)/){next;}
318318
if (($$4 == "FUNC") && ($$5 == "GLOBAL") && ($$6 == "DEFAULT")) {

linuxkm/linuxkm_wc_port.h

Lines changed: 76 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,37 @@
135135
#endif
136136
extern void wc_linuxkm_relax_long_loop(void);
137137

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+
138169
#ifdef BUILDING_WOLFSSL
139170

140171
#if ((LINUX_VERSION_CODE >= KERNEL_VERSION(5, 16, 0)) || \
@@ -408,33 +439,6 @@
408439
#endif /* !__PIE__ */
409440
#endif /* LINUXKM_LKCAPI_REGISTER */
410441

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-
438442
#ifndef WC_CHECK_FOR_INTR_SIGNALS
439443
#define WC_CHECK_FOR_INTR_SIGNALS() wc_linuxkm_check_for_intr_signals()
440444
#endif
@@ -453,15 +457,11 @@
453457
#if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && \
454458
defined(CONFIG_X86)
455459

456-
enum wc_svr_flags {
457-
WC_SVR_FLAG_INHIBIT = 1,
458-
};
459-
460460
extern __must_check int allocate_wolfcrypt_linuxkm_fpu_states(void);
461461
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);
465465

466466
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
467467
#include <asm/i387.h>
@@ -471,14 +471,14 @@
471471
#endif
472472
#ifndef CAN_SAVE_VECTOR_REGISTERS
473473
#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))
475475
#else
476-
#define CAN_SAVE_VECTOR_REGISTERS() can_save_vector_registers_x86()
476+
#define CAN_SAVE_VECTOR_REGISTERS() wc_can_save_vector_registers_x86()
477477
#endif
478478
#endif
479479
#ifndef SAVE_VECTOR_REGISTERS
480480
#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); \
482482
if (_svr_ret != 0) { \
483483
fail_clause \
484484
} \
@@ -489,22 +489,22 @@
489489
#define SAVE_VECTOR_REGISTERS2() ({ \
490490
int _fuzzer_ret = SAVE_VECTOR_REGISTERS2_fuzzer(); \
491491
(_fuzzer_ret == 0) ? \
492-
save_vector_registers_x86(0) : \
492+
wc_save_vector_registers_x86(0) : \
493493
_fuzzer_ret; \
494494
})
495495
#else
496-
#define SAVE_VECTOR_REGISTERS2() save_vector_registers_x86(0)
496+
#define SAVE_VECTOR_REGISTERS2() wc_save_vector_registers_x86(0)
497497
#endif
498498
#endif
499499
#ifndef RESTORE_VECTOR_REGISTERS
500-
#define RESTORE_VECTOR_REGISTERS() restore_vector_registers_x86()
500+
#define RESTORE_VECTOR_REGISTERS() wc_restore_vector_registers_x86()
501501
#endif
502502

503503
#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)
505505
#endif
506506
#ifndef REENABLE_VECTOR_REGISTERS
507-
#define REENABLE_VECTOR_REGISTERS() restore_vector_registers_x86()
507+
#define REENABLE_VECTOR_REGISTERS() wc_restore_vector_registers_x86()
508508
#endif
509509

510510
#elif defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && (defined(CONFIG_ARM) || defined(CONFIG_ARM64))
@@ -544,7 +544,7 @@
544544
#endif
545545

546546
#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.
548548
#endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */
549549

550550
_Pragma("GCC diagnostic pop");
@@ -765,12 +765,12 @@
765765

766766
#ifdef CONFIG_X86
767767
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;
769769
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;
772772
#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.
774774
#endif /* arch */
775775

776776
#endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */
@@ -1046,12 +1046,12 @@
10461046

10471047
#if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && defined(CONFIG_X86)
10481048
#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)
10501050
#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)
10531053
#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.
10551055
#endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */
10561056

10571057
#define __mutex_init WC_LKM_INDIRECT_SYM(__mutex_init)
@@ -1179,6 +1179,25 @@
11791179

11801180
#endif /* BUILDING_WOLFSSL */
11811181

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+
11821201
/* Copied from wc_port.h: For FIPS keep the function names the same */
11831202
#ifdef HAVE_FIPS
11841203
#define wc_InitMutex InitMutex
@@ -1232,6 +1251,12 @@
12321251
return 0;
12331252
}
12341253
#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+
12351260
typedef struct wolfSSL_Mutex {
12361261
spinlock_t lock;
12371262
unsigned long irq_flags;

linuxkm/lkcapi_sha_glue.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,6 +980,9 @@ static inline void wc_linuxkm_drbg_ctx_clear(struct wc_linuxkm_drbg_ctx * ctx)
980980
if (ctx->rngs[i].lock != 0) {
981981
/* better to leak than to crash. */
982982
pr_err("BUG: wc_linuxkm_drbg_ctx_clear called with DRBG #%d still locked.", i);
983+
ctx->rngs = NULL;
984+
ctx->n_rngs = 0;
985+
return;
983986
}
984987
else
985988
wc_FreeRng(&ctx->rngs[i].rng);

linuxkm/module_hooks.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -672,10 +672,10 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void) {
672672

673673
#if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && defined(CONFIG_X86)
674674
wolfssl_linuxkm_pie_redirect_table.allocate_wolfcrypt_linuxkm_fpu_states = allocate_wolfcrypt_linuxkm_fpu_states;
675-
wolfssl_linuxkm_pie_redirect_table.can_save_vector_registers_x86 = can_save_vector_registers_x86;
675+
wolfssl_linuxkm_pie_redirect_table.wc_can_save_vector_registers_x86 = wc_can_save_vector_registers_x86;
676676
wolfssl_linuxkm_pie_redirect_table.free_wolfcrypt_linuxkm_fpu_states = free_wolfcrypt_linuxkm_fpu_states;
677-
wolfssl_linuxkm_pie_redirect_table.restore_vector_registers_x86 = restore_vector_registers_x86;
678-
wolfssl_linuxkm_pie_redirect_table.save_vector_registers_x86 = save_vector_registers_x86;
677+
wolfssl_linuxkm_pie_redirect_table.wc_restore_vector_registers_x86 = wc_restore_vector_registers_x86;
678+
wolfssl_linuxkm_pie_redirect_table.wc_save_vector_registers_x86 = wc_save_vector_registers_x86;
679679
#elif defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS)
680680
#error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unsupported architecture.
681681
#endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */

0 commit comments

Comments
 (0)