Skip to content

Commit bd3370f

Browse files
committed
tegra Yocto fips fixes
Signed-off-by: Sameeh Jubran <sameeh.j@gmail.com>
1 parent 3062d15 commit bd3370f

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

linuxkm/linuxkm_wc_port.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,27 @@
2424
#ifndef LINUXKM_WC_PORT_H
2525
#define LINUXKM_WC_PORT_H
2626

27+
/*
28+
* CRITICAL: Disable ARM64 LSE atomics for out-of-tree modules.
29+
*
30+
* When CONFIG_ARM64_LSE_ATOMICS is enabled, the kernel uses static keys
31+
* (jump labels) in system_uses_lse_atomics() to choose between LSE and
32+
* LL/SC atomic implementations at runtime. These static keys generate
33+
* asm goto statements that reference .jump_table section symbols which
34+
* cannot be resolved in out-of-tree modules, causing:
35+
* "error: impossible constraint in 'asm'"
36+
*
37+
* By undefining CONFIG_ARM64_LSE_ATOMICS here (before any kernel headers
38+
* that use atomics are included), we force use of the LL/SC fallback path
39+
* which works correctly in out-of-tree modules.
40+
*
41+
* This must appear BEFORE #include <linux/version.h> because that header
42+
* may transitively include headers that use atomics.
43+
*/
44+
#ifdef CONFIG_ARM64_LSE_ATOMICS
45+
#undef CONFIG_ARM64_LSE_ATOMICS
46+
#endif
47+
2748
#include <linux/version.h>
2849

2950
#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 16, 0)
@@ -916,7 +937,12 @@
916937

917938
#endif /* WOLFSSL_USE_SAVE_VECTOR_REGISTERS */
918939

940+
#ifndef CONFIG_PREEMPT_RT
919941
typeof(__mutex_init) *__mutex_init;
942+
#else
943+
void (*__mutex_init)(struct mutex *lock, const char *name, struct lock_class_key *key);
944+
#endif
945+
920946
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
921947
typeof(mutex_lock_nested) *mutex_lock_nested;
922948
#else
@@ -1023,6 +1049,7 @@
10231049
#endif
10241050

10251051
#ifdef CONFIG_ARM64
1052+
#ifndef CONFIG_ARCH_TEGRA
10261053
#ifdef WC_CONTAINERIZE_THIS
10271054
/* alt_cb_patch_nops and queued_spin_lock_slowpath are defined early
10281055
* to allow shimming in system headers, but now we need the native
@@ -1037,6 +1064,7 @@
10371064
typeof(queued_spin_lock_slowpath) *queued_spin_lock_slowpath;
10381065
#endif
10391066
#endif
1067+
#endif
10401068

10411069
typeof(preempt_count) *preempt_count;
10421070
#ifndef _raw_spin_lock_irqsave
@@ -1235,7 +1263,9 @@
12351263
#error WOLFSSL_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture.
12361264
#endif /* WOLFSSL_USE_SAVE_VECTOR_REGISTERS */
12371265

1266+
#ifndef CONFIG_PREEMPT_RT
12381267
#define __mutex_init WC_PIE_INDIRECT_SYM(__mutex_init)
1268+
#endif
12391269
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
12401270
#define mutex_lock_nested WC_PIE_INDIRECT_SYM(mutex_lock_nested)
12411271
#else
@@ -1298,8 +1328,12 @@
12981328

12991329
/* this is defined in linux/spinlock.h as an inline that calls the unshimmed
13001330
* raw_spin_unlock_irqrestore(). use a macro here to supersede it.
1331+
* Note: On PREEMPT_RT kernels, spinlock_t doesn't have rlock member,
1332+
* so we skip this redefinition and use the kernel's native implementation.
13011333
*/
1334+
#ifndef CONFIG_PREEMPT_RT
13021335
#define spin_unlock_irqrestore(lock, flags) raw_spin_unlock_irqrestore(&((lock)->rlock), flags)
1336+
#endif
13031337

13041338
#define wc_linuxkm_sig_ignore_begin WC_PIE_INDIRECT_SYM(wc_linuxkm_sig_ignore_begin);
13051339
#define wc_linuxkm_sig_ignore_end WC_PIE_INDIRECT_SYM(wc_linuxkm_sig_ignore_end);

linuxkm/module_hooks.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include <wolfssl/wolfcrypt/libwolfssl_sources.h>
2525

2626
#ifndef WOLFSSL_LICENSE
27-
#define WOLFSSL_LICENSE "GPL"
27+
#define WOLFSSL_LICENSE "wolfSSL Commercial"
2828
#endif
2929

3030
#ifdef WOLFCRYPT_ONLY
@@ -1310,7 +1310,9 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void) {
13101310
#error WOLFSSL_USE_SAVE_VECTOR_REGISTERS is set for an unsupported architecture.
13111311
#endif /* WOLFSSL_USE_SAVE_VECTOR_REGISTERS */
13121312

1313-
wolfssl_linuxkm_pie_redirect_table.__mutex_init = __mutex_init;
1313+
#ifndef CONFIG_PREEMPT_RT
1314+
wolfssl_linuxkm_pie_redirect_table.__mutex_init = __mutex_init;
1315+
#endif
13141316
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
13151317
wolfssl_linuxkm_pie_redirect_table.mutex_lock_nested = mutex_lock_nested;
13161318
#else
@@ -1489,8 +1491,10 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void) {
14891491
#endif
14901492

14911493
#ifdef CONFIG_ARM64
1494+
#ifndef CONFIG_ARCH_TEGRA
14921495
wolfssl_linuxkm_pie_redirect_table.alt_cb_patch_nops = alt_cb_patch_nops;
14931496
wolfssl_linuxkm_pie_redirect_table.queued_spin_lock_slowpath = queued_spin_lock_slowpath;
1497+
#endif
14941498
#endif
14951499

14961500
wolfssl_linuxkm_pie_redirect_table.wc_linuxkm_sig_ignore_begin = wc_linuxkm_sig_ignore_begin;

wolfcrypt/src/wc_port.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4977,6 +4977,7 @@ char* wolfSSL_strnstr(const char* s1, const char* s2, unsigned int n)
49774977

49784978
#if defined(WOLFSSL_LINUXKM) && defined(CONFIG_ARM64) && \
49794979
defined(WC_SYM_RELOC_TABLES)
4980+
#ifndef CONFIG_ARCH_TEGRA
49804981
noinstr void my__alt_cb_patch_nops(struct alt_instr *alt, __le32 *origptr,
49814982
__le32 *updptr, int nr_inst)
49824983
{
@@ -4990,3 +4991,4 @@ void my__queued_spin_lock_slowpath(struct qspinlock *lock, u32 val)
49904991
(lock, val);
49914992
}
49924993
#endif
4994+
#endif

0 commit comments

Comments
 (0)