Skip to content

Commit 558f9d9

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

File tree

3 files changed

+78
-4
lines changed

3 files changed

+78
-4
lines changed

linuxkm/linuxkm_wc_port.h

Lines changed: 66 additions & 3 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,15 @@
916937

917938
#endif /* WOLFSSL_USE_SAVE_VECTOR_REGISTERS */
918939

919-
typeof(__mutex_init) *__mutex_init;
940+
#ifndef CONFIG_PREEMPT_RT
941+
typeof(__mutex_init) *__mutex_init;
942+
#else
943+
typeof(__rt_mutex_init) *__rt_mutex_init;
944+
typeof(rt_mutex_base_init) *rt_mutex_base_init;
945+
typeof(rt_spin_lock) *rt_spin_lock;
946+
typeof(rt_spin_unlock) *rt_spin_unlock;
947+
#endif
948+
920949
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
921950
typeof(mutex_lock_nested) *mutex_lock_nested;
922951
#else
@@ -1023,6 +1052,7 @@
10231052
#endif
10241053

10251054
#ifdef CONFIG_ARM64
1055+
#ifndef CONFIG_ARCH_TEGRA
10261056
#ifdef WC_CONTAINERIZE_THIS
10271057
/* alt_cb_patch_nops and queued_spin_lock_slowpath are defined early
10281058
* to allow shimming in system headers, but now we need the native
@@ -1037,6 +1067,7 @@
10371067
typeof(queued_spin_lock_slowpath) *queued_spin_lock_slowpath;
10381068
#endif
10391069
#endif
1070+
#endif
10401071

10411072
typeof(preempt_count) *preempt_count;
10421073
#ifndef _raw_spin_lock_irqsave
@@ -1235,7 +1266,17 @@
12351266
#error WOLFSSL_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture.
12361267
#endif /* WOLFSSL_USE_SAVE_VECTOR_REGISTERS */
12371268

1238-
#define __mutex_init WC_PIE_INDIRECT_SYM(__mutex_init)
1269+
#ifndef CONFIG_PREEMPT_RT
1270+
#define __mutex_init WC_PIE_INDIRECT_SYM(__mutex_init)
1271+
#else
1272+
/* On RT kernels, __mutex_init is a macro pointing to __rt_mutex_init */
1273+
#undef __mutex_init
1274+
#define __rt_mutex_init WC_PIE_INDIRECT_SYM(__rt_mutex_init)
1275+
#define __mutex_init(mutex, name, key) __rt_mutex_init(mutex, name, key)
1276+
#define rt_mutex_base_init WC_PIE_INDIRECT_SYM(rt_mutex_base_init)
1277+
#define rt_spin_lock WC_PIE_INDIRECT_SYM(rt_spin_lock)
1278+
#define rt_spin_unlock WC_PIE_INDIRECT_SYM(rt_spin_unlock)
1279+
#endif
12391280
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
12401281
#define mutex_lock_nested WC_PIE_INDIRECT_SYM(mutex_lock_nested)
12411282
#else
@@ -1298,8 +1339,30 @@
12981339

12991340
/* this is defined in linux/spinlock.h as an inline that calls the unshimmed
13001341
* raw_spin_unlock_irqrestore(). use a macro here to supersede it.
1342+
* Note: On PREEMPT_RT kernels, spinlock_t doesn't have rlock member,
1343+
* so we skip this redefinition and use the kernel's native implementation.
13011344
*/
1302-
#define spin_unlock_irqrestore(lock, flags) raw_spin_unlock_irqrestore(&((lock)->rlock), flags)
1345+
#ifndef CONFIG_PREEMPT_RT
1346+
#define spin_unlock_irqrestore(lock, flags) raw_spin_unlock_irqrestore(&((lock)->rlock), flags)
1347+
#else
1348+
/* Undo internal wolfSSL PIE macro rewriting */
1349+
#ifdef rt_spin_unlock
1350+
#undef rt_spin_unlock
1351+
#endif
1352+
#ifdef rt_spin_lock
1353+
#undef rt_spin_lock
1354+
#endif
1355+
static inline void wolfssl_spin_unlock_irqrestore_rt(spinlock_t *lock,
1356+
unsigned long flags)
1357+
{
1358+
(void)flags; /* rt_spin_unlock ignores flags */
1359+
wolfssl_linuxkm_pie_redirect_table.rt_spin_unlock(lock);
1360+
}
1361+
1362+
#undef spin_unlock_irqrestore
1363+
#define spin_unlock_irqrestore(lock, flags) \
1364+
wolfssl_spin_unlock_irqrestore_rt((lock), (flags))
1365+
#endif
13031366

13041367
#define wc_linuxkm_sig_ignore_begin WC_PIE_INDIRECT_SYM(wc_linuxkm_sig_ignore_begin);
13051368
#define wc_linuxkm_sig_ignore_end WC_PIE_INDIRECT_SYM(wc_linuxkm_sig_ignore_end);

linuxkm/module_hooks.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,14 @@ 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+
#else
1316+
wolfssl_linuxkm_pie_redirect_table.__rt_mutex_init = __rt_mutex_init;
1317+
wolfssl_linuxkm_pie_redirect_table.rt_mutex_base_init = rt_mutex_base_init;
1318+
wolfssl_linuxkm_pie_redirect_table.rt_spin_lock = rt_spin_lock;
1319+
wolfssl_linuxkm_pie_redirect_table.rt_spin_unlock = rt_spin_unlock;
1320+
#endif
13141321
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
13151322
wolfssl_linuxkm_pie_redirect_table.mutex_lock_nested = mutex_lock_nested;
13161323
#else
@@ -1489,8 +1496,10 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void) {
14891496
#endif
14901497

14911498
#ifdef CONFIG_ARM64
1499+
#ifndef CONFIG_ARCH_TEGRA
14921500
wolfssl_linuxkm_pie_redirect_table.alt_cb_patch_nops = alt_cb_patch_nops;
14931501
wolfssl_linuxkm_pie_redirect_table.queued_spin_lock_slowpath = queued_spin_lock_slowpath;
1502+
#endif
14941503
#endif
14951504

14961505
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)