mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 19:24:42 +02:00
linuxkm/linuxkm_memory.c: fix circular dependency around wolfCrypt_Init(), allocate_wolfcrypt_linuxkm_fpu_states(), wc_linuxkm_fpu_state_assoc(), on FIPS.
This commit is contained in:
@@ -116,6 +116,10 @@ static union wc_linuxkm_fpu_savebuf {
|
|||||||
WARN_UNUSED_RESULT int allocate_wolfcrypt_linuxkm_fpu_states(void)
|
WARN_UNUSED_RESULT int allocate_wolfcrypt_linuxkm_fpu_states(void)
|
||||||
{
|
{
|
||||||
if (wc_linuxkm_fpu_states != NULL) {
|
if (wc_linuxkm_fpu_states != NULL) {
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
/* see note below in wc_linuxkm_fpu_state_assoc_unlikely(). */
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
static int warned_for_repeat_alloc = 0;
|
static int warned_for_repeat_alloc = 0;
|
||||||
if (! warned_for_repeat_alloc) {
|
if (! warned_for_repeat_alloc) {
|
||||||
pr_err("attempt at repeat allocation"
|
pr_err("attempt at repeat allocation"
|
||||||
@@ -123,6 +127,7 @@ WARN_UNUSED_RESULT int allocate_wolfcrypt_linuxkm_fpu_states(void)
|
|||||||
warned_for_repeat_alloc = 1;
|
warned_for_repeat_alloc = 1;
|
||||||
}
|
}
|
||||||
return BAD_STATE_E;
|
return BAD_STATE_E;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LINUXKM_FPU_STATES_FOLLOW_THREADS
|
#ifdef LINUXKM_FPU_STATES_FOLLOW_THREADS
|
||||||
@@ -225,6 +230,18 @@ static struct wc_thread_fpu_count_ent *wc_linuxkm_fpu_state_assoc(int create_p)
|
|||||||
static int _warned_on_null = 0;
|
static int _warned_on_null = 0;
|
||||||
if (wc_linuxkm_fpu_states == NULL)
|
if (wc_linuxkm_fpu_states == NULL)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
/* FIPS needs to use SHA256 for the core verify HMAC, before
|
||||||
|
* reaching the regular wolfCrypt_Init() logic. to break the
|
||||||
|
* dependency loop on intelasm builds, we allocate here.
|
||||||
|
* this is not thread-safe and doesn't need to be.
|
||||||
|
*/
|
||||||
|
int ret = allocate_wolfcrypt_linuxkm_fpu_states();
|
||||||
|
if (ret == 0) {
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
if (_warned_on_null == 0) {
|
if (_warned_on_null == 0) {
|
||||||
pr_err("wc_linuxkm_fpu_state_assoc called by pid %d"
|
pr_err("wc_linuxkm_fpu_state_assoc called by pid %d"
|
||||||
" before allocate_wolfcrypt_linuxkm_fpu_states.\n", my_pid);
|
" before allocate_wolfcrypt_linuxkm_fpu_states.\n", my_pid);
|
||||||
@@ -233,6 +250,7 @@ static struct wc_thread_fpu_count_ent *wc_linuxkm_fpu_state_assoc(int create_p)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
i_endptr = &wc_linuxkm_fpu_states[wc_linuxkm_fpu_states_n_tracked];
|
i_endptr = &wc_linuxkm_fpu_states[wc_linuxkm_fpu_states_n_tracked];
|
||||||
|
|
||||||
@@ -282,6 +300,18 @@ static struct wc_thread_fpu_count_ent *wc_linuxkm_fpu_state_assoc_unlikely(int c
|
|||||||
static int _warned_on_null = 0;
|
static int _warned_on_null = 0;
|
||||||
if (wc_linuxkm_fpu_states == NULL)
|
if (wc_linuxkm_fpu_states == NULL)
|
||||||
{
|
{
|
||||||
|
#ifdef HAVE_FIPS
|
||||||
|
/* FIPS needs to use SHA256 for the core verify HMAC, before
|
||||||
|
* reaching the regular wolfCrypt_Init() logic. to break the
|
||||||
|
* dependency loop on intelasm builds, we allocate here.
|
||||||
|
* this is not thread-safe and doesn't need to be.
|
||||||
|
*/
|
||||||
|
int ret = allocate_wolfcrypt_linuxkm_fpu_states();
|
||||||
|
if (ret == 0) {
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
if (_warned_on_null == 0) {
|
if (_warned_on_null == 0) {
|
||||||
pr_err("wc_linuxkm_fpu_state_assoc called by pid %d"
|
pr_err("wc_linuxkm_fpu_state_assoc called by pid %d"
|
||||||
" before allocate_wolfcrypt_linuxkm_fpu_states.\n", my_pid);
|
" before allocate_wolfcrypt_linuxkm_fpu_states.\n", my_pid);
|
||||||
@@ -290,6 +320,7 @@ static struct wc_thread_fpu_count_ent *wc_linuxkm_fpu_state_assoc_unlikely(int c
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
slot = &wc_linuxkm_fpu_states[my_cpu];
|
slot = &wc_linuxkm_fpu_states[my_cpu];
|
||||||
slot_pid = __atomic_load_n(&slot->pid, __ATOMIC_CONSUME);
|
slot_pid = __atomic_load_n(&slot->pid, __ATOMIC_CONSUME);
|
||||||
@@ -419,6 +450,18 @@ static inline void wc_linuxkm_fpu_state_release(
|
|||||||
__atomic_store_n(&ent->pid, 0, __ATOMIC_RELEASE);
|
__atomic_store_n(&ent->pid, 0, __ATOMIC_RELEASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WARN_UNUSED_RESULT int can_save_vector_registers_x86(void)
|
||||||
|
{
|
||||||
|
if (irq_fpu_usable())
|
||||||
|
return 1;
|
||||||
|
else if (in_nmi() || (hardirq_count() > 0) || (softirq_count() > 0))
|
||||||
|
return 0;
|
||||||
|
else if (test_thread_flag(TIF_NEED_FPU_LOAD))
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
WARN_UNUSED_RESULT int save_vector_registers_x86(void)
|
WARN_UNUSED_RESULT int save_vector_registers_x86(void)
|
||||||
{
|
{
|
||||||
#ifdef LINUXKM_FPU_STATES_FOLLOW_THREADS
|
#ifdef LINUXKM_FPU_STATES_FOLLOW_THREADS
|
||||||
|
Reference in New Issue
Block a user