Skip to content

Commit ef3a1a2

Browse files
committed
linuxkm/linuxkm_wc_port.h, linuxkm/module_hooks.c, and wolfcrypt/src/wc_port.c: fixes for spinlocks on CONFIG_ARM64;
wolfcrypt/src/wc_port.c: include random.h, for Entropy_Init().
1 parent 688bc16 commit ef3a1a2

File tree

3 files changed

+47
-10
lines changed

3 files changed

+47
-10
lines changed

linuxkm/linuxkm_wc_port.h

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@
126126

127127
#if defined(__PIE__) && defined(CONFIG_ARM64)
128128
#define alt_cb_patch_nops my__alt_cb_patch_nops
129+
#define queued_spin_lock_slowpath my__queued_spin_lock_slowpath
129130
#endif
130131

131132
#include <linux/kernel.h>
@@ -705,20 +706,30 @@
705706

706707
#ifdef CONFIG_ARM64
707708
#ifdef __PIE__
708-
/* alt_cb_patch_nops defined early to allow shimming in system
709-
* headers, but now we need the native one.
709+
/* alt_cb_patch_nops and queued_spin_lock_slowpath are defined early
710+
* to allow shimming in system headers, but now we need the native
711+
* ones.
710712
*/
711713
#undef alt_cb_patch_nops
712714
typeof(my__alt_cb_patch_nops) *alt_cb_patch_nops;
715+
#undef queued_spin_lock_slowpath
716+
typeof(my__queued_spin_lock_slowpath) *queued_spin_lock_slowpath;
713717
#else
714718
typeof(alt_cb_patch_nops) *alt_cb_patch_nops;
719+
typeof(queued_spin_lock_slowpath) *queued_spin_lock_slowpath;
715720
#endif
716721
#endif
717722

718723
typeof(preempt_count) *preempt_count;
719-
typeof(_raw_spin_lock_irqsave) *_raw_spin_lock_irqsave;
720-
typeof(_raw_spin_trylock) *_raw_spin_trylock;
721-
typeof(_raw_spin_unlock_irqrestore) *_raw_spin_unlock_irqrestore;
724+
#ifndef _raw_spin_lock_irqsave
725+
typeof(_raw_spin_lock_irqsave) *_raw_spin_lock_irqsave;
726+
#endif
727+
#ifndef _raw_spin_trylock
728+
typeof(_raw_spin_trylock) *_raw_spin_trylock;
729+
#endif
730+
#ifndef _raw_spin_unlock_irqrestore
731+
typeof(_raw_spin_unlock_irqrestore) *_raw_spin_unlock_irqrestore;
732+
#endif
722733
typeof(_cond_resched) *_cond_resched;
723734

724735
const void *_last_slot;
@@ -885,9 +896,19 @@
885896

886897
#undef preempt_count /* just in case -- not a macro on x86. */
887898
#define preempt_count (wolfssl_linuxkm_get_pie_redirect_table()->preempt_count)
888-
#define _raw_spin_lock_irqsave (wolfssl_linuxkm_get_pie_redirect_table()->_raw_spin_lock_irqsave)
889-
#define _raw_spin_trylock (wolfssl_linuxkm_get_pie_redirect_table()->_raw_spin_trylock)
890-
#define _raw_spin_unlock_irqrestore (wolfssl_linuxkm_get_pie_redirect_table()->_raw_spin_unlock_irqrestore)
899+
900+
#ifndef WOLFSSL_LINUXKM_USE_MUTEXES
901+
#ifndef _raw_spin_lock_irqsave
902+
#define _raw_spin_lock_irqsave (wolfssl_linuxkm_get_pie_redirect_table()->_raw_spin_lock_irqsave)
903+
#endif
904+
#ifndef _raw_spin_trylock
905+
#define _raw_spin_trylock (wolfssl_linuxkm_get_pie_redirect_table()->_raw_spin_trylock)
906+
#endif
907+
#ifndef _raw_spin_unlock_irqrestore
908+
#define _raw_spin_unlock_irqrestore (wolfssl_linuxkm_get_pie_redirect_table()->_raw_spin_unlock_irqrestore)
909+
#endif
910+
#endif
911+
891912
#define _cond_resched (wolfssl_linuxkm_get_pie_redirect_table()->_cond_resched)
892913

893914
/* this is defined in linux/spinlock.h as an inline that calls the unshimmed
@@ -991,8 +1012,8 @@
9911012

9921013
static inline int wc_LockMutex(wolfSSL_Mutex* m)
9931014
{
994-
if (in_nmi() || in_hardirq() || in_softirq())
995-
return BAD_STATE_E;
1015+
if (in_nmi() || hardirq_count() || in_softirq())
1016+
return -1;
9961017
mutex_lock(m);
9971018
return 0;
9981019
}

linuxkm/module_hooks.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,13 +658,20 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void) {
658658
#endif
659659

660660
wolfssl_linuxkm_pie_redirect_table.preempt_count = my_preempt_count;
661+
#ifndef _raw_spin_lock_irqsave
661662
wolfssl_linuxkm_pie_redirect_table._raw_spin_lock_irqsave = _raw_spin_lock_irqsave;
663+
#endif
664+
#ifndef _raw_spin_trylock
662665
wolfssl_linuxkm_pie_redirect_table._raw_spin_trylock = _raw_spin_trylock;
666+
#endif
667+
#ifndef _raw_spin_unlock_irqrestore
663668
wolfssl_linuxkm_pie_redirect_table._raw_spin_unlock_irqrestore = _raw_spin_unlock_irqrestore;
669+
#endif
664670
wolfssl_linuxkm_pie_redirect_table._cond_resched = _cond_resched;
665671

666672
#ifdef CONFIG_ARM64
667673
wolfssl_linuxkm_pie_redirect_table.alt_cb_patch_nops = alt_cb_patch_nops;
674+
wolfssl_linuxkm_pie_redirect_table.queued_spin_lock_slowpath = queued_spin_lock_slowpath;
668675
#endif
669676

670677
/* runtime assert that the table has no null slots after initialization. */

wolfcrypt/src/wc_port.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
#endif
2727

2828
#include <wolfssl/wolfcrypt/cpuid.h>
29+
#ifdef HAVE_ENTROPY_MEMUSE
30+
#include <wolfssl/wolfcrypt/random.h>
31+
#endif
2932
#ifdef HAVE_ECC
3033
#include <wolfssl/wolfcrypt/ecc.h>
3134
#endif
@@ -4628,4 +4631,10 @@ noinstr void my__alt_cb_patch_nops(struct alt_instr *alt, __le32 *origptr,
46284631
return (wolfssl_linuxkm_get_pie_redirect_table()->
46294632
alt_cb_patch_nops)(alt, origptr, updptr, nr_inst);
46304633
}
4634+
4635+
void my__queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
4636+
{
4637+
return (wolfssl_linuxkm_get_pie_redirect_table()->
4638+
queued_spin_lock_slowpath)(lock, val);
4639+
}
46314640
#endif

0 commit comments

Comments
 (0)