Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .wolfssl_known_macro_extras
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ CONFIG_WOLFSSL_XMSS
CONFIG_WOLFTPM
CONFIG_WOLFTPM_EXAMPLE_NAME_ESPRESSIF
CONFIG_X86
CONFIG_X86_64
CONV_WITH_DIV
CPA_CY_API_VERSION_NUM_MAJOR
CPA_CY_API_VERSION_NUM_MINOR
Expand Down Expand Up @@ -799,6 +800,7 @@ WC_STM32_RNG_DIAG
WC_STM32_RNG_NO_NIST_INIT
WC_STM32_SAES_DIAG
WC_STRICT_SIG
WC_SVR_DONT_USE_NATIVE_REG_BUFS
WC_USE_PIE_FENCEPOSTS_FOR_FIPS
WC_WANT_FLAG_DONT_USE_VECTOR_OPS
WIFIESPAT
Expand Down
23 changes: 17 additions & 6 deletions linuxkm/linuxkm_wc_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@
#endif
#endif

#if defined(WC_SVR_DONT_USE_NATIVE_REG_BUFS)
#undef WC_SVR_USE_NATIVE_REG_BUFS
#elif defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && !defined(WC_SVR_USE_NATIVE_REG_BUFS)
#define WC_SVR_USE_NATIVE_REG_BUFS
#endif

#if defined(HAVE_FIPS) && FIPS_VERSION3_LT(7, 0, 0)
#if defined(HAVE_HASHDRBG) && \
defined(HAVE_ENTROPY_MEMUSE) && \
Expand Down Expand Up @@ -740,8 +746,13 @@
#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && \
defined(CONFIG_X86)

extern __must_check int allocate_wolfcrypt_linuxkm_fpu_states(void);
extern void free_wolfcrypt_linuxkm_fpu_states(void);
extern __must_check int wc_linuxkm_allocate_svr_states(void);
extern void wc_linuxkm_free_svr_states(void);
WOLFSSL_API void wc_svr_disallowed_count_reset(void);
#ifdef WC_SVR_USE_NATIVE_REG_BUFS
WOLFSSL_LOCAL __must_check int wc_linuxkm_svr_native_is_ready(void);
#endif
WOLFSSL_API __must_check unsigned long long int wc_svr_disallowed_count_current(void);
WOLFSSL_API __must_check int wc_can_save_vector_registers_x86(void);
WOLFSSL_API __must_check int wc_save_vector_registers_x86(enum wc_svr_flags flags);
WOLFSSL_API void wc_restore_vector_registers_x86(enum wc_svr_flags flags);
Expand Down Expand Up @@ -1247,9 +1258,9 @@
#ifdef WOLFSSL_USE_SAVE_VECTOR_REGISTERS

#ifdef CONFIG_X86
typeof(allocate_wolfcrypt_linuxkm_fpu_states) *allocate_wolfcrypt_linuxkm_fpu_states;
typeof(wc_linuxkm_allocate_svr_states) *wc_linuxkm_allocate_svr_states;
typeof(wc_can_save_vector_registers_x86) *wc_can_save_vector_registers_x86;
typeof(free_wolfcrypt_linuxkm_fpu_states) *free_wolfcrypt_linuxkm_fpu_states;
typeof(wc_linuxkm_free_svr_states) *wc_linuxkm_free_svr_states;
typeof(wc_restore_vector_registers_x86) *wc_restore_vector_registers_x86;
typeof(wc_save_vector_registers_x86) *wc_save_vector_registers_x86;
#else /* !CONFIG_X86 */
Expand Down Expand Up @@ -1606,9 +1617,9 @@
#define get_current WC_PIE_INDIRECT_SYM(get_current)

#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && defined(CONFIG_X86)
#define allocate_wolfcrypt_linuxkm_fpu_states WC_PIE_INDIRECT_SYM(allocate_wolfcrypt_linuxkm_fpu_states)
#define wc_linuxkm_allocate_svr_states WC_PIE_INDIRECT_SYM(wc_linuxkm_allocate_svr_states)
#define wc_can_save_vector_registers_x86 WC_PIE_INDIRECT_SYM(wc_can_save_vector_registers_x86)
#define free_wolfcrypt_linuxkm_fpu_states WC_PIE_INDIRECT_SYM(free_wolfcrypt_linuxkm_fpu_states)
#define wc_linuxkm_free_svr_states WC_PIE_INDIRECT_SYM(wc_linuxkm_free_svr_states)
#define wc_restore_vector_registers_x86 WC_PIE_INDIRECT_SYM(wc_restore_vector_registers_x86)
#define wc_save_vector_registers_x86 WC_PIE_INDIRECT_SYM(wc_save_vector_registers_x86)
#elif defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
Expand Down
9 changes: 8 additions & 1 deletion linuxkm/lkcapi_sha_glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2123,7 +2123,9 @@ static int wc_linuxkm_rng_bank_init(struct wc_rng_bank *ctx)
int ret;
word32 flags = WC_RNG_BANK_FLAG_CAN_WAIT;

#if defined(HAVE_FIPS) && FIPS_VERSION3_LT(7,0,0)
#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && \
!defined(WC_SVR_USE_NATIVE_REG_BUFS) && \
defined(HAVE_FIPS) && FIPS_VERSION3_LT(7,0,0)
/* before v7, the SHA-2 implementations couldn't dynamically switch between
* C and asm in a given wc_Sha256 instance.
*/
Expand Down Expand Up @@ -2205,6 +2207,11 @@ static struct wc_rng_bank_inst *linuxkm_get_drbg(struct wc_rng_bank *ctx) {
WC_RNG_BANK_FLAG_CAN_WAIT |
WC_RNG_BANK_FLAG_PREFER_AFFINITY_INST;

#ifdef WC_SVR_USE_NATIVE_REG_BUFS
if (wc_linuxkm_svr_native_is_ready())
flags |= WC_RNG_BANK_FLAG_AFFINITY_LOCK;
else
#endif
if (wc_linuxkm_can_block())
flags |= WC_RNG_BANK_FLAG_AFFINITY_LOCK;
else
Expand Down
10 changes: 7 additions & 3 deletions linuxkm/module_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,14 @@ int wc_lkm_LockMutex(wolfSSL_Mutex* m)
m->irq_flags = irq_flags;
return 0;
}
if (irq_count() != 0) {
if (! wc_linuxkm_can_block()) {
/* Note, this catches calls while SAVE_VECTOR_REGISTERS()ed as
* required, because in_softirq() is always true while saved,
* even for WC_FPU_INHIBITED_FLAG contexts.
*
* It also catches non-interrupt atomic callers -- tasks holding a
* spinlock or running with IRQs off -- which must not reach the
* cond_resched() retry loop below.
*/
spin_lock_irqsave(&m->lock, irq_flags);
m->irq_flags = irq_flags;
Expand Down Expand Up @@ -1522,9 +1526,9 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void) {
wolfssl_linuxkm_pie_redirect_table.get_current = my_get_current_thread;

#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && defined(CONFIG_X86)
wolfssl_linuxkm_pie_redirect_table.allocate_wolfcrypt_linuxkm_fpu_states = allocate_wolfcrypt_linuxkm_fpu_states;
wolfssl_linuxkm_pie_redirect_table.wc_linuxkm_allocate_svr_states = wc_linuxkm_allocate_svr_states;
wolfssl_linuxkm_pie_redirect_table.wc_can_save_vector_registers_x86 = wc_can_save_vector_registers_x86;
wolfssl_linuxkm_pie_redirect_table.free_wolfcrypt_linuxkm_fpu_states = free_wolfcrypt_linuxkm_fpu_states;
wolfssl_linuxkm_pie_redirect_table.wc_linuxkm_free_svr_states = wc_linuxkm_free_svr_states;
wolfssl_linuxkm_pie_redirect_table.wc_restore_vector_registers_x86 = wc_restore_vector_registers_x86;
wolfssl_linuxkm_pie_redirect_table.wc_save_vector_registers_x86 = wc_save_vector_registers_x86;
#elif defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
Expand Down
29 changes: 29 additions & 0 deletions linuxkm/simd_hammer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Makefile for simd_hammer.ko -- stress testing for kernel FPU/SIMD context handling
#
# Copyright (C) 2006-2026 wolfSSL Inc.
#
# This file is part of wolfSSL.
#
# wolfSSL is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# wolfSSL is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA

obj-m := simd_hammer.o

KDIR ?= /lib/modules/$(shell uname -r)/build

default:
$(MAKE) -C $(KDIR) M=$(CURDIR) modules

clean:
$(MAKE) -C $(KDIR) M=$(CURDIR) clean
Loading
Loading