Skip to content

Commit 3fdfc69

Browse files
committed
kernel: add patch to fix Xavier NX crashes
It's unclear the reason, but randomly, Xavier NX systems would crash immediately upon booting into the kernel. This would happen while initial entropy from the UEFI RNG table. This appears to be working in 35.5.0, and this patch from the stable kernel is what is needed.
1 parent b25c55b commit 3fdfc69

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
From 72268945b124cd61336f9b4cac538b0516399a2d Mon Sep 17 00:00:00 2001
2+
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
3+
Date: Tue, 7 Jun 2022 10:40:05 +0200
4+
Subject: [PATCH] Revert "random: use static branch for crng_ready()"
5+
6+
This reverts upstream commit f5bda35fba615ace70a656d4700423fa6c9bebee
7+
from stable. It's not essential and will take some time during 5.19 to
8+
work out properly.
9+
10+
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
11+
---
12+
drivers/char/random.c | 12 ++----------
13+
1 file changed, 2 insertions(+), 10 deletions(-)
14+
15+
diff --git a/drivers/char/random.c b/drivers/char/random.c
16+
index c206db96f60a..5776dfd4a6fc 100644
17+
--- a/drivers/char/random.c
18+
+++ b/drivers/char/random.c
19+
@@ -79,8 +79,7 @@ static enum {
20+
CRNG_EARLY = 1, /* At least POOL_EARLY_BITS collected */
21+
CRNG_READY = 2 /* Fully initialized with POOL_READY_BITS collected */
22+
} crng_init __read_mostly = CRNG_EMPTY;
23+
-static DEFINE_STATIC_KEY_FALSE(crng_is_ready);
24+
-#define crng_ready() (static_branch_likely(&crng_is_ready) || crng_init >= CRNG_READY)
25+
+#define crng_ready() (likely(crng_init >= CRNG_READY))
26+
/* Various types of waiters for crng_init->CRNG_READY transition. */
27+
static DECLARE_WAIT_QUEUE_HEAD(crng_init_wait);
28+
static struct fasync_struct *fasync;
29+
@@ -110,11 +109,6 @@ bool rng_is_initialized(void)
30+
}
31+
EXPORT_SYMBOL(rng_is_initialized);
32+
33+
-static void __cold crng_set_ready(struct work_struct *work)
34+
-{
35+
- static_branch_enable(&crng_is_ready);
36+
-}
37+
-
38+
/* Used by wait_for_random_bytes(), and considered an entropy collector, below. */
39+
static void try_to_generate_entropy(void);
40+
41+
@@ -268,7 +262,7 @@ static void crng_reseed(void)
42+
++next_gen;
43+
WRITE_ONCE(base_crng.generation, next_gen);
44+
WRITE_ONCE(base_crng.birth, jiffies);
45+
- if (!static_branch_likely(&crng_is_ready))
46+
+ if (!crng_ready())
47+
crng_init = CRNG_READY;
48+
spin_unlock_irqrestore(&base_crng.lock, flags);
49+
memzero_explicit(key, sizeof(key));
50+
@@ -711,7 +705,6 @@ static void extract_entropy(void *buf, size_t len)
51+
52+
static void __cold _credit_init_bits(size_t bits)
53+
{
54+
- static struct execute_work set_ready;
55+
unsigned int new, orig, add;
56+
unsigned long flags;
57+
58+
@@ -727,7 +720,6 @@ static void __cold _credit_init_bits(size_t bits)
59+
60+
if (orig < POOL_READY_BITS && new >= POOL_READY_BITS) {
61+
crng_reseed(); /* Sets crng_init to CRNG_READY under base_crng.lock. */
62+
- execute_in_process_context(crng_set_ready, &set_ready);
63+
process_random_ready_list();
64+
wake_up_interruptible(&crng_init_wait);
65+
kill_fasync(&fasync, SIGIO, POLL_IN);
66+
--
67+
2.44.0
68+

kernel/default.nix

+5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ pkgsAarch64.buildLinux (args // {
8989

9090
# Lower priority of tegra-se crypto modules since they're slow and flaky
9191
{ patch = ./0008-Lower-priority-of-tegra-se-crypto.patch; }
92+
93+
# Include patch from linux-stable that (for some reason) appears to fix
94+
# random crashes very early in boot process on Xavier NX specifically
95+
# Remove when updating to 35.5.0
96+
{ patch = ./0009-Revert-random-use-static-branch-for-crng_ready.patch; }
9297
] ++ kernelPatches;
9398

9499
structuredExtraConfig = with lib.kernel; {

0 commit comments

Comments
 (0)